[DB-SIG] pyodbc on osx?

Chris Clark Chris.Clark at ingres.com
Mon Aug 14 19:42:27 CEST 2006


Chris Curvey wrote:
> I really like the pyodbc package for getting to MS-SQL on Windows.  
> Has anyone been able to make this work with ODBC drivers on OSX?  (Or 
> is there another open source solution that works?)

I've not tried it personally, I get the impression pyodbc is Windows 
focused at the moment, you might could try emailing Michael directly and 
ask him. he is very approachable and good at responding to mail.

Asking the obvious question first ;-)  I'm assuming that you don't have 
a python driver for the database you need on OSX, hence the ODBC 
requirement?

One alternative is the Ingres DBI driver (GPL license), one of the less 
well known features is that it is ODBC based. We've successfully built 
with UnixODBC but this isn't the classic deployment option. Supporting 
other ODBC drivers isn't a primary feature but is a stretch goal.

If you want to pull down the latest release from 
http://www.ingres.com/products/Prod_Download_Python_DBI.html and apply a 
little patch and play with it, I'd love to get some feedback/patches.

    === ingres!main!generic!common!pydbi setup.py rev 25 ====
    136c136
    < libraries=["iiodbc.1","m", "c"]
    ---
    > libraries=["odbc","m", "c"]
    171c171
    <     include_dirs=[ii_system_files,"hdr/"],
    ---
    >     include_dirs=["/disk3/unixODBC-2.2.11/include/","hdr/"],
    173c173
    <     library_dirs=[ii_system_lib],
    ---
    >     library_dirs=["/usr/lib"],
    === ingres!main!generic!common!pydbi!dbi ingresdbi.c rev 24 ====
    5432c5432
    <     case SQL_BIT_VARYING:
    ---
    > //    case SQL_BIT_VARYING:

NOTE hard coded paths in code as this is a quick patch! Modify accordingly

You can just use a dsn to connect (or use the not yet well documented 
connection string parameter "connectstr=").

    import ingresdbi
    dc=ingresdbi.connect(dsn='localdb')
    #dc=ingresdbi.connect(connectstr='DSN=localdb')
    c=dc.cursor()
    c.execute("select * from mytable")

    print c.description
    print c.fetchall()

IngresDBI has not been tested under OSX but it has been tested on a 
bunch of other platforms so I can't imagine any platform issues (famous 
last words...), you may find some Ingres'isms in there but if you wanted 
to #ifdef them that would be a neat patch that I would like to see.

Finally, other options for odbc and Python (under Unix like systems) 
include mxODBC and the SQL Relay.

Hope this helps get you started, good luck!

Chris



More information about the DB-SIG mailing list