python使用ceODBC连接sybase iq 12.7 数据库
时间:2010-08-06 来源:zhangzhu1984
python使用ceODBC连接sybase iq 12.7 数据库
官方说是有sqlanydb可以连接到iq,但是我没成功,因为报错:ENG=node2_asiqdemo 太长了。。。
官方连接:http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01087.1520/html/iqnew1520/CEGHAFJI.htm
1)下载ceODBC安装包
http://ceodbc.sourceforge.net/
我下载的是 ceODBC-2.0.tar.gz
2)源码安装
tar -zxvf ceODBC-2.0.tar.gz
阅读readme.txt
安装需要的包
python-dev
unixodbc
unixodbc-dev 我选择rpm包安装了上面三个包 rpm -vih /tmp/python-devel-2.4.3-27.el5.* rpm -vih /tmp/unixODBC-2.2.11-7.1.* rpm -vih /tmp/unixODBC-devel-2.2.11-7.1. 编译 python setup.py build 安装 python setup.py install 测试 Python 2.4.3 (#1, Jun 11 2009, 14:09:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ceODBC
>>> 无报错,则安装成功
>>> 3)安装sqlanywhere11 安装到/opt/sqlanywhere11/目录 将cat /opt/sqlanywhere11/bin64/sa_config.sh 文件的内容添加到 ~/.bash_profile #!/bin/sh
#
echo "iAnywhere Solutions, Inc. One Sybase Drive, Dublin, CA 94568, USA"
echo "Copyright (c) 2001-2008, iAnywhere Solutions, Inc. Portions copyright (c) "
echo "1988-2008, Sybase, Inc. All rights reserved. All unpublished rights reserved."
echo # comment the following to unset the SA location.
SQLANY11="/opt/sqlanywhere11"
export SQLANY11 # comment the following lines to remove SA binaries from your path.
PATH="$SQLANY11/bin64:$SQLANY11/bin32:${PATH:-}"
export PATH
LD_LIBRARY_PATH="$SQLANY11/lib64:${LD_LIBRARY_PATH:-}"
LD_LIBRARY_PATH="$SQLANY11/lib32:${LD_LIBRARY_PATH:-}"
export LD_LIBRARY_PATH 4)编辑 .odbc.ini 文件,放在当前用户的根目录下面 内容如下: =====================分割线=============== [x]
Driver=/opt/sqlanywhere11/lib64/libodbc.so
uid=DBA
pwd=SQL
ENG=node2_asiqdemo
CommLinks=tcp(host=10.25.115.20;port=2638)
DatabaseName=asiqdemo =====================分割线=============== 第一行:sybase的驱动 第二行:用户 第三行:密码 第四行:要注意哦,是数据库服务器的名称node2_asiqdemo 第五行:连接参数,是主机和端口 第六行:数据库名 5)新建python脚本,测试连接,脚本内容如下: import ceODBC con=ceODBC.connect('dsn=x;uid=DBA;pwd=SQL')
curser=con.cursor()
curser.execute("select count(1) from a1") for i in curser.fetchone():
print i
con.commit() 执行脚本 [root@vm12 ~]# python 3.py 表a1一共48行记录
48
到此安装成功! 2010-08-05
unixodbc
unixodbc-dev 我选择rpm包安装了上面三个包 rpm -vih /tmp/python-devel-2.4.3-27.el5.* rpm -vih /tmp/unixODBC-2.2.11-7.1.* rpm -vih /tmp/unixODBC-devel-2.2.11-7.1. 编译 python setup.py build 安装 python setup.py install 测试 Python 2.4.3 (#1, Jun 11 2009, 14:09:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ceODBC
>>> 无报错,则安装成功
>>> 3)安装sqlanywhere11 安装到/opt/sqlanywhere11/目录 将cat /opt/sqlanywhere11/bin64/sa_config.sh 文件的内容添加到 ~/.bash_profile #!/bin/sh
#
echo "iAnywhere Solutions, Inc. One Sybase Drive, Dublin, CA 94568, USA"
echo "Copyright (c) 2001-2008, iAnywhere Solutions, Inc. Portions copyright (c) "
echo "1988-2008, Sybase, Inc. All rights reserved. All unpublished rights reserved."
echo # comment the following to unset the SA location.
SQLANY11="/opt/sqlanywhere11"
export SQLANY11 # comment the following lines to remove SA binaries from your path.
PATH="$SQLANY11/bin64:$SQLANY11/bin32:${PATH:-}"
export PATH
LD_LIBRARY_PATH="$SQLANY11/lib64:${LD_LIBRARY_PATH:-}"
LD_LIBRARY_PATH="$SQLANY11/lib32:${LD_LIBRARY_PATH:-}"
export LD_LIBRARY_PATH 4)编辑 .odbc.ini 文件,放在当前用户的根目录下面 内容如下: =====================分割线=============== [x]
Driver=/opt/sqlanywhere11/lib64/libodbc.so
uid=DBA
pwd=SQL
ENG=node2_asiqdemo
CommLinks=tcp(host=10.25.115.20;port=2638)
DatabaseName=asiqdemo =====================分割线=============== 第一行:sybase的驱动 第二行:用户 第三行:密码 第四行:要注意哦,是数据库服务器的名称node2_asiqdemo 第五行:连接参数,是主机和端口 第六行:数据库名 5)新建python脚本,测试连接,脚本内容如下: import ceODBC con=ceODBC.connect('dsn=x;uid=DBA;pwd=SQL')
curser=con.cursor()
curser.execute("select count(1) from a1") for i in curser.fetchone():
print i
con.commit() 执行脚本 [root@vm12 ~]# python 3.py 表a1一共48行记录
48
到此安装成功! 2010-08-05
相关阅读 更多 +