[Tutor] Talking to mssql?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sat Apr 9 02:47:11 CEST 2005


On Sat, 9 Apr 2005, j2 wrote:

> Well, doesn't fly for me, because I can't install it. Can you offer any
> help on the below?

Hi J2,

This is a slightly specialized question for tutor; you might be able to
get some better help by asking on the db-sig mailing list:

    http://mail.python.org/mailman/listinfo/db-sig

You may want to look at:

    http://pymssql.sourceforge.net/

too, which may work better with FreeTDS.  I'm guessing that you are using
FreeTDS, the Sybase library implementation, from the GCC output that you
included earlier.


>From a first glance, I think that the compilation errors are trying to say
that the C compiler can't find certain symbols that it expects to see.
These include:

    DBVARYCHAR
    DBBIT


According to:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dblibc/dbc_pdcapb_6vvm.asp

those types are valid in SQL Server 2000.  So everything should be fine.


Wait.  Ok, got it.  You are using the FreeTDS libraries!  If so, that's
probably the problem: I don't see the type definitions for those two types
in sybdb.h from the FreeTDS libraries:

    http://www.freetds.org/reference/a00265.html

So I think this is the problem: there are holes in the FreeTDS
implementation of Sybase that make it incompatible with David Cole's MSSQL
Python library.


... Ok, I found some more information on this.  It appears that some folks
have written a workaround by editing the mssqldb.h in the MSSQL Python
module.  I don't speak Russian, but from:

    http://itconnection.ru/pipermail/zopyrus/2003-September/070093.html

it looks like MSSQL needs to be modified slightly to support FreeTDS
better.  The message above defines a customized definition of DBBIT and
DBVARYCHAR.


Add the following to the mssqldb.h file in the MSSQL Python module:

######
#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
######

and then try recompiling.


I do not know if this is really the right thing to do: you really should
follow up by talking with David Cole, the developer of MSSQL, to see his
thoughts on this.  Can you follow up on this?  Here's a link to the
mailing list:

    https://object-craft.com.au/cgi-bin/mailman/listinfo/python-sybase


Anyway, hope this helps!



More information about the Tutor mailing list