[Zope-DB] MS SQL Server module for Python

Jaroslav Lukeš jaroslav.lukes at k-net.cz
Mon Aug 23 05:19:16 EDT 2004


Dear Sir,

I have successfully compiled and run MS SQL server module for python with my
Zope as I was advice in 

http://mail.zope.org/pipermail/zope-db/2004-May/003067.html

But with datatype LONGTEXT I was problem for long, long time. But Today I was
found small hack, see follow. 

Only one problem occurs - it reads 4096 chars only due dbcollen=4096. When I
try to hack MSSQL.py to read more, it reads still maximum of 4096 chars per
column. It is limit in sybase or it is problem in somewhere else?

I have linux machine with:
	python 2.1.3
	Sybase ASE 11.9.2
	mssql-0.09.tar.gz
		-->mssqldb.so size 289335 bytes

And Windows machine with:
	Windows 2k (?)
	MS SQL server 2000


Result on-screen:

[root at webproxy Z MS SQL DA with Sessions]# /var/zope/bin/python
Python 2.1.3 (#1, Apr 15 2002, 11:13:45)
[GCC 2.7.2.3] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import MSSQL
MSSQL.set_debug(open('debug.txt', 'w'))
>>> MSSQL.set_debug(open('debug.txt', 'w'))
>>> db = MSSQL.connect('xxxxx','user', 'password','xxxx','pubs')
c.execute('select logged_at from jobs where job_id=4611')
>>> c = db.cursor()
>>> c.fetchone()
(Apr 27 2004  6:50:00:000AM,)
>>> c.execute('select notes from jobs where job_id=4611')
>>> c.fetchone()
Segmentation fault (core dumped)


[root at webproxy Z MS SQL DA with Sessions]# cat debug.txt
dblogin() -> OK
DBSETLUSER('user') -> SUCCEED
DBSETLPWD('password') -> SUCCEED
dbopen('xxxxx') -> OK
dbuse('xxxxx') -> SUCCEED
dbcancel() -> SUCCEED
dbcmd('select logged_at from jobs where job_id=4611') -> SUCCEED
dbsqlexec() -> SUCCEED
dbresults() -> SUCCEED
dbnumcols() -> 1
dbcoltype(1) -> SQLDATETIME
dbcollen(1) -> 8
dbbind(1, DATETIMEBIND, 0, 0x81196f0) -> SUCCEED
dbcolname(1) -> 'logged_at'
dbnextrow() -> REG_ROW
dbdatlen(1) -> 8
dbcancel() -> SUCCEED
dbcmd('select notes from jobs where job_id=4611') -> SUCCEED
dbsqlexec() -> SUCCEED
dbresults() -> SUCCEED
dbnumcols() -> 1
dbcoltype(1) -> SQLTEXT
dbcollen(1) -> 4096
dbbind(1, DBBUFFER, 0, 0x8139ce8) -> SUCCEED
dbcolname(1) -> 'notes'
[root at webproxy Z MS SQL DA with Sessions]#


When I change in MSSQL.py from SQLCHAR to SQLBINARY (line 150), no coredump
now and data fetched, WOW!:

def _row_bind(dbproc):
    '''Bind buffers for column data.
    '''
    num_cols = dbproc.dbnumcols()
    bufs = []
    for i in range(1, num_cols + 1):
        coltype = dbproc.dbcoltype(i)
        if coltype == SQLTEXT:
            coltype = SQLBINARY
                      ^^^^^^^^^

It is question if it is the right method, but it is functional and it does
not make zope hangs. But it reads max. 4096 chars only.

If it is possible, would you like to update your sources, please?

Many thanks,

J. Lukesh


More information about the Zope-DB mailing list