Chinaunix首页 | 论坛 | 博客
  • 博客访问: 356321
  • 博文数量: 49
  • 博客积分: 2709
  • 博客等级: 少校
  • 技术积分: 890
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-01 16:19
文章分类

全部博文(49)

文章存档

2013年(1)

2012年(5)

2011年(5)

2010年(5)

2009年(6)

2008年(27)

我的朋友

分类: Sybase

2010-08-06 16:58:07

python使用ceODBC连接sybase iq 12.7 数据库
    
 
官方说是有sqlanydb可以连接到iq,但是我没成功,因为报错:ENG=node2_asiqdemo 太长了。。。
官方连接:
 
1)下载ceODBC安装包
    
    我下载的是 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
 
 

 
 
 
阅读(4725) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~