[数据库测试]强烈推荐一个python ODBC数据源插件,可支持Oracle,Db2,Mysql,Sql-server以及各种数据库版本,附例子和测试程序
来源:互联网 发布:闪图制作软件 编辑:程序博客网 时间:2024/04/29 15:27
今天有很多时间,再与大家分享一个最近使用的到第三方控件,个人认为对设计一些数据库测试脚本非常有用。
首先,请访问这个地址:http://www.egenix.com/products/python/mxODBC/,此控件是一个ODBC的通用插件。
这为我们通过Windows系统,制作各种测试脚本提供很好操作平台。DB-API:http://www.python.org/dev/peps/pep-0249/
Download
A successful installation of mxODBC requires these three steps:
Before continuing with the download of mxODBC, first make sure that you have installed the eGenix.com mx Base Distribution, since the eGenix.com mxODBC Distribution is an add-on to our base set of Python extensions.
The downloads below do not contain any license keys. You will either have to obtain evaluation licenses or buy production licenses in order to successfully install and use the package.
Select the right download for your platform and Python version and then head on to the installation instructions below.
IMPORTANT:
By downloading, installing or using the eGenix mxODBC Distribution, you agree to the terms and conditions set forth in the eGenix.com Commercial License Agreement 1.2.0.
Redistribution of these files is not allowed. Please contact the eGenix Sales Team for details about redistribution possibilities and terms.
A successful installation of mxODBC requires these three steps:
Before continuing with the download of mxODBC, first make sure that you have installed the eGenix.com mx Base Distribution, since the eGenix.com mxODBC Distribution is an add-on to our base set of Python extensions.
The downloads below do not contain any license keys. You will either have to obtain evaluation licenses or buy production licenses in order to successfully install and use the package.
Select the right download for your platform and Python version and then head on to the installation instructions below.
IMPORTANT:
By downloading, installing or using the eGenix mxODBC Distribution, you agree to the terms and conditions set forth in the eGenix.com Commercial License Agreement 1.2.0.
Redistribution of these files is not allowed. Please contact the eGenix Sales Team for details about redistribution possibilities and terms.
下载控件清单:
egenix-mx-base-3.0.0.win32-py2.5.ms
egenix-mx-experimental-3.0.0.win32-py2.5.msiegenix-mxodbc-3.0.1.win32-py2.5.msi
注册License
eGenix.com Commercial License Agreement 1.2.0,注意填好后,Liscense会被发送到邮箱
Lincense拷贝的路径,本机地址:C:/Python25/Lib/site-packages/mx/ODBC
如果没有注册Liscense,会有如下提示:
以下提供一段测试程序,该段程序为清除Db2中的两表数据:
# -*- coding: cp936 -*-
import mx.ODBC
import mx.ODBC.Windows
IDLE中提示:
Traceback (most recent call last):
File "E: tpSearch_Table.py", line 3, in <module>
import mx.ODBC.Windows
File "mxODBCWindows__init__.py", line 9, in <module>
ImportError: initialization of module mxODBC failed (<class 'mx.ODBC.Windows.LicenseError'>:mx.ODBC.license could not be loaded; please visit the http://www.egenix.com/ web-site to obtain a license file or write to licenses@egenix.com for information.)
提取有效部分:license could not be loaded; please visit the http://www.egenix.com/ web-site to obtain a license file or write to licenses@egenix.com for information
import mx.ODBC
import mx.ODBC.Windows
IDLE中提示:
Traceback (most recent call last):
File "E: tpSearch_Table.py", line 3, in <module>
import mx.ODBC.Windows
File "mxODBCWindows__init__.py", line 9, in <module>
ImportError: initialization of module mxODBC failed (<class 'mx.ODBC.Windows.LicenseError'>:mx.ODBC.license could not be loaded; please visit the http://www.egenix.com/ web-site to obtain a license file or write to licenses@egenix.com for information.)
提取有效部分:license could not be loaded; please visit the http://www.egenix.com/ web-site to obtain a license file or write to licenses@egenix.com for information
# -*- coding: cp936 -*-
import mx.ODBC
import mx.ODBC.Windows
import sys, os ,time
class db2_test():
def __init__(self, tablename1, tablename2):
self.tablename1 = tablename1
self.tablename2 = tablename2
print self.tablename1, self.tablename2
#清除任意制定表数据
def truncate_table(self):
db = mx.ODBC.Windows.DriverConnect( 'DSN=infospy' )
cursor = db.cursor()
cursor.execute("ALTER TABLE %s ACTIVATE NOT LOGGED INITiALLY WITH EMPTY TABLE;" % (self.tablename1))
cursor.execute("ALTER TABLE %s ACTIVATE NOT LOGGED INITiALLY WITH EMPTY TABLE;" % (self.tablename2))
cursor.execute("Commit;")
cursor.close()
db.close()
print "表%s;%s; 清除数据成功!" % (self.tablename1, self.tablename2)
if __name__ == "__main__":
tablename1 = "test_table_1"
tablename2 = "test_table_2"
db2 = db2_test(tablename1, tablename2)
db2.truncate_table()
time.sleep(3)
sys.exit(1)
import mx.ODBC
import mx.ODBC.Windows
import sys, os ,time
class db2_test():
def __init__(self, tablename1, tablename2):
self.tablename1 = tablename1
self.tablename2 = tablename2
print self.tablename1, self.tablename2
#清除任意制定表数据
def truncate_table(self):
db = mx.ODBC.Windows.DriverConnect( 'DSN=infospy' )
cursor = db.cursor()
cursor.execute("ALTER TABLE %s ACTIVATE NOT LOGGED INITiALLY WITH EMPTY TABLE;" % (self.tablename1))
cursor.execute("ALTER TABLE %s ACTIVATE NOT LOGGED INITiALLY WITH EMPTY TABLE;" % (self.tablename2))
cursor.execute("Commit;")
cursor.close()
db.close()
print "表%s;%s; 清除数据成功!" % (self.tablename1, self.tablename2)
if __name__ == "__main__":
tablename1 = "test_table_1"
tablename2 = "test_table_2"
db2 = db2_test(tablename1, tablename2)
db2.truncate_table()
time.sleep(3)
sys.exit(1)
db = mx.ODBC.Windows.DriverConnect( 'DSN=infospy' ) DSN为在WindowsODBC中配置的数据源名
有关ODBC配置,此贴略。由于时间关系,详细的API请查询文章中所给的地址。
- [数据库测试]强烈推荐一个python ODBC数据源插件,可支持Oracle,Db2,Mysql,Sql-server以及各种数据库版本,附例子和测试程序
- [数据库测试]强烈推荐一个python ODBC数据源插件,可支持Oracle,Db2,Mysql,Sql-server以及各种数据库版本,附例子和测试程序
- [数据库测试]强烈推荐一个python ODBC数据源插件,可支持Oracle,Db2,Mysql,Sql-server以及各种数据库版本,附例子和测试程序
- [数据库测试]强烈推荐一个python ODBC数据源插件,可支持Oracle,Db2,Mysql,Sql-server以及各种数据库版本,附例子和测试程序
- JAVA连接各种数据库(mysql,sql server,oracle,db2)
- C#连接各种数据库代码Access,Sql Server,Oracle,Mysql,IBM DB2,Sybase
- 各种数据库(MYSQL、Oracle、DB2、SQL Server、PostgreSQL)的分页查询语句
- mysql,oracle,sql server,sybase数据库数据模拟器java,支持各种数据库,夸平台
- C#连接Access、SQL Server、Oracle、MySQL、DB2和SyBase六种不同数据库的程序源码
- 关于数据库 SQL Server 和 Oracle 以及 MySQL
- java连接数据库(mysql,sql server,oracle,db2)
- 【数据库安全管理教程】oracle DB2 SQL server MySQL
- C#连接Access、SQL Server、Oracle、MySQL、DB2和SyBase数据库的代码集
- C#连接Access、SQL Server、Oracle、MySQL、DB2和SyBase数据库的代码集
- win10 数据库SQL Server的安装之SQL Server 和 Oracle 以及 MySQL 有哪些区别
- mysql:ADO连接mysql数据库,驱动程序和ODBC数据源问题
- 图解各种数据库数据源(ODBC)配置
- 数据库关键字 (Oracle, SQL Server, DB2)
- 一天一苹果,医生远离我~
- Ping程序在TCP/IP中的应用
- 值得珍藏一辈子的80句话(经典语句)
- 人生成功生涯规划100诀
- linux常用命令全集
- [数据库测试]强烈推荐一个python ODBC数据源插件,可支持Oracle,Db2,Mysql,Sql-server以及各种数据库版本,附例子和测试程序
- 关于相互包含的头文件
- jQuery - 参考资料 - Filter Property (Tabular Data Control): - Filter属性(表格数据控件)
- 贡献自己以前在网上搜索和总结的两个通用的数据库公用操作类
- C#设计模式-Builder生成器模式
- 基本上潜心工作了一天
- DataBinder.Eval 显示YYYY-MM-DD的日期型格式
- 15个顶级技术博客网址共享
- kerberos 1.13 by Рустем Фасихов