sybase iq16 python 访问接口
cd /opt/sybiq/IQ-16_0/sdk/python
python setup.py build
python setup.py install
以上为安装python 驱动接口
其中 copy 文件失败的地方,先将 /usr/lib/python2.6/site-packages 目录权限改为777 copy 完成后复原
再重新 python setup.py install
vi scripts/test.py
import sqlanydb
con = sqlanydb.connect(userid='DBA', password='sql',eng='querydb')
cur = con.cursor()
cur.execute('select count(*) from TEST')
assert cur.fetchone()[0] > 0
con.close()
print('sqlanydb successfully installed.')
python 连接 sybiq16 数据库
执行
python test.py
vi test4.py
import sqlanydb
# Create a connection object, then use it to create a cursor
con = sqlanydb.connect(userid='DBA', password='sql',eng='querydb')
cursor = con.cursor()
# Execute a SQL string
sql = "exec sp_iqstatus"
cursor.execute(sql)
# Get a cursor description which contains column names
desc = cursor.description
print len(desc)
# Fetch all results from the cursor into a sequence,
# display the values as column name=value pairs,
# and then close the connection
rowset = cursor.fetchall()
for row in rowset:
for col in range(len(desc)):
print "%s=%s" % (desc[col][0], row[col] )
print
cursor.close()
con.close()
输出 sp_iqstatus 的执行结果
Name=Sybase IQ (TM)
Value=Copyright (c) 1992-2013 by SAP AG or an SAP affiliate company. All rights reserved.
Name= Version:
Value=16.0.0.637/140123/P/sp02/Enterprise Linux64 - x86_64 - 2.6.18-194.el5/64bit/2014-01-23 02:48:12
Name= Time Now:
Value=2015-02-04 13:58:09.232
Name= Build Time:
Value=2014-01-23 02:48:12
Name= File Format:
Value=23 on 03/18/1999
结果如上所示