sybase iq16 python 访问接口

zyhlhx 2015-02-04 03:29:57
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
结果如上所示
...全文
2070 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
huangting0117 2017-04-21
  • 打赏
  • 举报
回复
python 3.6好像不行哦
  • 打赏
  • 举报
回复
嗯。 不错。
zyhlhx 2015-02-04
  • 打赏
  • 举报
回复
vi test5.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 = "SELECT top 10 * FROM TEST" 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()

2,596

社区成员

发帖
与我相关
我的任务
社区描述
Sybase相关技术讨论区
社区管理员
  • Sybase社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧