使用Python2.4在Linux下访问SQL Server(安装篇)

以前用Python访问MSSQL用一个叫pymssql的模块,只在windows下用过,挺好用的。具体说明见这里
http://pymssql.sourceforge.net/

现在需要在Linux下用Python访问MSSQL,安装了FreeTDS(http://www.freetds.org/)。由于这几天pymssql的源代码无法下载,Debian上也没有这个包下载,只好用FreeTDS文档中提到的Python MSSQL module(http://object-craft.com.au/projects/mssql/examples.html),下载下来按照文档执行 python setup.py install,
编译错误,出现下边的提示:
running install
running build
running build_py
running build_ext
building 'mssqldb' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_FREETDS -DHAVE_DBALTBIND -DHAVE_DBCLROPT -DHAVE_DBCURCMD -DHAVE_DBCURROW -DHAVE_DBISOPT -DHAVE_DBNUMCOMPUTE -DHAVE_DBRETTYPE -I/usr/include -I/home/hjue/Python-2.4.2/Include -I/home/hjue/Python-2.4.2 -c databuf.c -o build/temp.linux-i686-2.4/databuf.o
In file included from databuf.c:9:
mssqldb.h:59: error: syntax error at '##' token
mssqldb.h:59: error: syntax error at '##' token
mssqldb.h:59: error: syntax error at '##' token
mssqldb.h:68: error: `DBMAXCHAR' undeclared here (not in a function)
mssqldb.h:71: error: syntax error at '##' token
mssqldb.h:71: error: syntax error at '##' token
mssqldb.h:71: error: syntax error at '##' token
error: command 'gcc' failed with exit status 1

在Google上查了一下,主要是因为关于MSSQL的一些变量没有定义。
在mssqldb.h 中加入下边代码,重新运行python setup.py install 就OK了

# define DBMAXCHAR 256
#ifdef HAVE_FREETDS  
typedef unsigned char DBBIT;
#define PRNUMERIC MAXPRECISION
#define DB_MAX_PREC MAXPRECISION
#define DB_MAX_SCALE MAXPRECISION
typedef struct dbvarychar
{                 
        DBSMALLINT  len;                 
        DBCHAR      str[DBMAXCHAR];
} DBVARYCHAR;        
#endif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

多鱼的夏天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值