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
结果如上所示
...全文
2073 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()
PostgreSQL是以加州大学伯克利分校计算机系开发的POSTGRES,现在已经更名为PostgreSQL. PostgreSQL支持大部分SQL标准并且提供了许多其它现代特性:复杂查询、外键、触发器、视图、事务完整性等。 PostgreSQL 是一个免费的对象-关系数据库服务器(数据库管理系统),它在灵活的 BSD-风格许可证下发行。它提供了相对其他开放源代码数据库系统(比如 MySQL 和 Firebird),和专有系统(比如 Oracle、Sybase、IBM 的 DB2 和 Microsoft SQL Server)之外的另一种选择。 事实上, PostgreSQL 的特性覆盖了 SQL-2/SQL-92 和 SQL-3/SQL-99,首先,它包括了可以说是目前世界上最丰富的数据类型的支持,其中有些数据类型可以说连商业数据库都不具备, 比如 IP 类型和几何类型等;其次,PostgreSQL 是全功能的自由软件数据库,很长时间以来,PostgreSQL 是唯一支持事务、子查询、多版本并行控制系统(MVCC)、数据完整性检查等特性的唯一的一种自由软件的数据库管理系统。 Inprise 的 InterBase 以及SAP等厂商将其原先专有软件开放为自由软件之后才打破了这个唯一。最后,PostgreSQL拥有一支非常活跃的开发队伍,而且在许多黑客的努力下,PostgreSQL 的质量日益提高。从技术角度来讲,PostgreSQL 采用的是比较经典的C/S(client/server)结构,也就是一个客户端对应一个服务器端守护进程的模式,这个守护进程分析客户端来的查询请求,生成规划树,进行数据检索并最终把结果格式化输出后返回给客户端。为了便于客户端的程序的编写,由数据库服务器提供了统一的客户端 C 接口。而不同的客户端接口都是源自这个 C 接口,比如ODBC,JDBC,Python,Perl,Tcl,C/C++,ESQL等, 同时也要指出的是,PostgreSQL 对接口的支持也是非常丰富的,几乎支持所有类型的数据库客户端接口。这一点也可以说是 PostgreSQL 一大优点。 本课程作为PostgreSQL数据库管理之三,主要讲解以下内容:1.     PostgreSQL约束讲解和剖析2.     PostgreSQL数据类型3.     PostgreSQL的结构管理4.     PostgreSQL条件表达式和操作5.     PostgreSQL使用小技巧

2,596

社区成员

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

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