MSSQL PyADO2 driver

"Tim Golden" <[email protected]> Fri, 27 May 2005 17:09:56 +0100 (BST)
Newsgroups gmane.comp.web.skunkweb
Message-ID <[email protected]>
I've knocked up a first-pass MSSQL driver for PyDO2 using
the adodbapi module. It's a bit rough-and-ready, but it
does manage to guess columns and to select. It's given
rise to a couple of questions:

1) Unicode: the PyDO2 code does a certain mixture of
   checking against str & basestring:

base.py:            if isinstance(f, str):
base.py:            elif isinstance(f, str):
base.py:            if not isinstance(qualifier, basestring):
base.py:            if isinstance(unique, (unicode,str)):
base.py:        if args and isinstance(args[0], str):
dbi.py:            if isinstance(o, str):
dbi.py:        elif not isinstance(order, str):
dbi.py:    if isinstance(driver, str):
joins.py:        if isinstance(on, basestring):
joins.py:            if isinstance(on[0], basestring):
operators.py:        if not isinstance(name, basestring):

   All the table names and data come back from adodbapi
   as Unicode objects
   and I'm not sure whether to change all the checks to
   consider unicode (ie to use basestring) or whether to
   determine the encoding -- however possible that is --
   and to decode from that, or what.

2) Sequences: MSSQL implements an IDENTITY
   column type. But... this needn't be a primary key
   (although, for obvious reasons they usually are).
   It needn't even be unique, since you can
   temporarily override the identity and insert a
   value directly. So, what does this mean in terms
   of PyDO2? Should we only consider IDENTITY to be
   sequence if they are also unique/pk? Or not?

3) Getting unique indexes is ridiculously hard, and
   I think I've got a working version, altho' I'm
   having to work around a quirk in the adodbapi code,
   which might or might not be considered a bug.

   In essense, in addition to picking up unique
   constraints (which is easy, but doesn't include
   simple unique indexes!) I'm checking sysindexes to see if
   there are any indexes at all. If there are, I'm
   calling sp_helpindex and parsing the fields. The
   alternative seems to be to mess around with sysindexes
   and spt_values. Have I missed something?

I'm quite willing to post a Subversion patch for anyone
who wants to try this out, but the whole thing's by no means
tested yet. I'm not sure what to do with conversions, for example.

TJG


-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005