python连接服务器informix_连接到Informix数据库 - Python方式

操作系统:RHEL 6U4 64bit 安装GCC

数据库版本:Informix 12.10.FC4

数据库连接工具版本:CSDK 4.10.FC4

所需要的软件包:

确认Python 2.6.6 及python-devel 2.6.6 已经安装

InformixDB Python API 2.50 下载地址:http://informixdb.sourceforge.net/

设置环境变量及sqlhosts(内容指向访问数据库)

.bash_profile

INFORMIXDIR=/home/informix

INFORMIXSERVER=db31

LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql

PATH=$INFORMIXDIR/bin:$PATH

export INFORMIXDIR INFORMIXSERVER LD_LIBRARY_PATH PATH

sqlhosts

db31 onsoctcp 192.168.80.64 12131

将InformixDB-2.5.zip 或者InformixDB-2.5.tar.gz 上传并解包。

使用root权限(带csdk环境变量),执行

python setup.py build_ext

python setup.py install

注:期间可能会有警告,只要能正确生成就OK

[root@rhel6u4 InformixDB-2.5]# python setup.py build_ext

running build_ext

/home/informix/bin/esql -EDHAVE_ESQL9 -EDHAVE_DESCRIBE_INPUT -e _informixdb.ec

building '_informixdb' extension

creating build/temp.linux-x86_64-2.6

creating build/temp.linux-x86_64-2.6/ext

gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPYTHON_INCLUDE=/usr/include/python2.6 -DHAVE_C_DATETIME=1 -DHAVE_PY_BOOL=1 -Iext -I/home/informix/incl/esql -I/usr/include/python2.6 -c ext/_informixdb.c -o build/temp.linux-x86_64-2.6/ext/_informixdb.o

_informixdb.ec: In function ‘get_bool_from_int’:

_informixdb.ec:125: warning: cast from pointer to integer of different size

_informixdb.ec: In function ‘set_bool_to_int’:

_informixdb.ec:139: warning: cast from pointer to integer of different size

_informixdb.ec: In function ‘dberror_value’:

_informixdb.ec:3385: warning: the address of ‘message’ will always evaluate as ‘true’

_informixdb.ec: In function ‘Sblob_init’:

_informixdb.ec:3808: warning: value computed is not used

_informixdb.ec:3813: warning: value computed is not used

_informixdb.ec:3819: warning: value computed is not used

_informixdb.ec:3825: warning: value computed is not used

_informixdb.ec:3835: warning: value computed is not used

_informixdb.ec:3845: warning: value computed is not used

_informixdb.ec:3851: warning: value computed is not used

_informixdb.ec:3857: warning: value computed is not used

_informixdb.ec: In function ‘Sblob_specget’:

_informixdb.ec:4129: warning: cast from pointer to integer of different size

_informixdb.ec:4160: warning: cast from pointer to integer of different size

creating build/lib.linux-x86_64-2.6

gcc -pthread -shared build/temp.linux-x86_64-2.6/ext/_informixdb.o /home/informix/lib/esql/checkapi.o -L/usr/lib64 -L/home/informix/lib/esql -L/home/informix/lib -lpython2.6 -lifsql -lifasf -lifgen -lifos -lifgls -lpthread -lm -ldl -lcrypt -lifglx -o build/lib.linux-x86_64-2.6/_informixdb.so

[root@rhel6u4 InformixDB-2.5]# python setup.py install

running install

running build

running build_py

copying informixdb.py -> build/lib.linux-x86_64-2.6

running build_ext

running install_lib

copying build/lib.linux-x86_64-2.6/_informixdb.so -> /usr/lib64/python2.6/site-packages

running install_egg_info

Removing /usr/lib64/python2.6/site-packages/InformixDB-2.5-py2.6.egg-info

Writing /usr/lib64/python2.6/site-packages/InformixDB-2.5-py2.6.egg-info

然后在/etc/ld.so.conf.d目录下增加 informix-x64.conf配置文件,内容如下:

/home/informix/lib

/home/informix/lib/esql

内容为LD_LIBRARY_PATH的两条记录,INFORMIXDIR目录以实际为准

执行ldconfig 使之生效

创建测试语句 t.py

#!/usr/bin/python

import sys

import informixdb # import the InformixDB module

conn = informixdb.connect("sysmaster")

cursor1 = conn.cursor(rowformat = informixdb.ROW_AS_DICT)

cursor1.execute('select tabid, tabname from systables')

for row in cursor1:

print "TABNAME: %d %-20s" % (row['tabid'], row['tabname'])

continue

conn.close()

sys.exit(0);

通过 python t.py执行,查看结果

[root@rhel6u4 InformixDB-2.5]# python t.py

TABNAME: 1 systables

TABNAME: 2 syscolumns

TABNAME: 3 sysindices

TABNAME: 4 systabauth

TABNAME: 5 syscolauth

TABNAME: 6 sysviews

TABNAME: 7 sysusers

TABNAME: 8 sysdepend

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值