[数据库测试]强烈推荐一个python ODBC数据源插件,可支持Oracle,Db2,Mysql,Sql-server以及各种数据库版本,附例子和测试程序

news/2024/7/3 8:41: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.

下载控件清单:

egenix-mx-base-3.0.0.win32-py2.5.ms

egenix-mx-experimental-3.0.0.win32-py2.5.msi

egenix-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

 

#  -*- 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 )

db = mx.ODBC.Windows.DriverConnect( 'DSN=infospy' ) DSN为在WindowsODBC中配置的数据源名

有关ODBC配置,此贴略。由于时间关系,详细的API请查询文章中所给的地址。

 





http://www.niftyadmin.cn/n/3647543.html

相关文章

【Leetcode】415. Add Strings

题目地址&#xff1a; https://leetcode.com/problems/add-strings/ 高精度加法&#xff0c;直接模拟人工加法。注意要逆序从个位开始加&#xff0c;然后最后再reverse回来。 class Solution {public String addStrings(String num1, String num2) {StringBuilder s new St…

CMPP和SMPP协议比较[转-理解短信中心协议原理]

CMPP和SMPP协议比较并非同类型协议CMPP和SMPP都是短信协议中的一种&#xff0c;但它们不是同一类型的协议。SMPP和ESME和SMC&#xff08;短信中心&#xff09;之间的协议&#xff0c;而CMPP是SP和中国移动ISMG之间的通讯协议。以下是CMPP 3.0文档中的图示。与CMPP对应的协议有&…

JVM字符串常量池及String的intern方法详解?深夜思考

前言 今天这篇文章是比较偏“教程”一点的文章。但也由浅入深&#xff0c;认真地分析了源码&#xff0c;并且介绍了一些在使用Spring Cache中常见的问题和解决方案&#xff0c;肯定是比简单的入门文档更有深度一些的&#xff0c;相信大家看了之后会有一定的收获。 数据库 2.…

AIX服务器上同步局域网PCtime时间

配置AIX成为NTP服务器&#xff08;使用Internet标准时间服务器&#xff09; 1、编辑/etc/ntp.conf文件&#xff1a; server time-b.timefreq.bldrdoc.gov prefer #Internet时间服务器地址 server 127.127.1.0 driftfile /etc/ntp.drift tracefile /etc/ntp.trace 2、和Internet…

Mybatis-plus常用API全套教程,分分钟搞定!

2021第一次Java面试&#xff0c;我去了快手。快手的面试挺有挑战性的&#xff0c;而且还特别有意思&#xff0c;感觉啥都能问到。&#xff08;二面是10天前约的面试&#xff0c;差点要忘了&#xff09;然后是HR面&#xff0c;前天我就收到offer。 如何保证缓存和数据库一致性 …

另类眼光看管理:企业生存的三条动物法则[转华为某人力经理]

饱读诗书的秀才下海经商&#xff0c;屡屡受挫之后&#xff0c;痛定思痛&#xff0c;终有所醒悟&#xff0c;虽有些极端&#xff0c;但却让人看到企业生存的现实。最近在芝加哥发生了一档有趣的事&#xff0c;三个年轻人带着一头羊拿着四张票要进球场去看棒球&#xff0c;把门儿…

Mycat和Mysql搭建高可用企业数据库集群,吊打面试官系列!

一、前言 最近刚读完一本书&#xff1a;《Netty、Zookeeper、Redis 并发实战》&#xff0c;个人觉得 Netty 部分是写得很不错的&#xff0c;读完之后又对 Netty 进行了一波很好的复习&#xff08;之前用 spring boot netty zookeeper 模仿 dubbo 做 rpc 框架&#xff0c;那时…