9. Getting Python Talking to ODBC

Egenix provide suitable Python libraries. A look at their Web page indicates that two packages are required:

    egenix-mx-commercial-2.0.6.tar.gz     # ...which requires...
    egenix-mx-base-2.0.5.tar.gz
I opted for the source code, rather than RPMs. Installation of each went like a dream: unpack the base first, then (following the README), simply
    python setup.py install
followed by the same for the commercial package.

(If I recall correctly there was one minor hiccup: libiodbc was required by the installation and whilst I have the libiodbc-3.51.1-1 RPM installed, the relevant library was not found --- a sym link was required

    /usr/lib/libiodbc.so -> libiodbc.so.2
Since I am using using UnixODBC rather than iODBC I could have played with the installation script and removed this requirement, but life's too short.)

The documentation comes with plenty of detail but no simple tutorial. A quick poke around Google suggested a simple session to try. Here is what happened:

  >>> import mx.ODBC.unixODBC
  >>> db = mx.ODBC.unixODBC.DriverConnect('DSN=vardywardy;UID=<ursusername>;PWD=<urspassword>')
  >>> c = db.cursor()
  >>> sql = "SELECT * FROM UserURSDetails WHERE NetwareAccountName = 'mpciish2'"
  >>> c.execute(sql)
  >>> print c.fetchall()
  [('Hood', 'Simon', '270002', '7270002', None, 'Information Systems Department', 'mpciish2', 270002, None, 'Y', 'Y', '', None, 45526, 45240, 79742, None, None, None, 'Staff', 'S', 'mpciish2', 'INT0037', 29, 270002, '900002700020', None, 0, 1, 'SENIOR COMPUTER OFFICER', None, None, None, None, 'UMIST', None)]
  >>> c.close()
How good is that?

...previousup (conts)next...



About this document:

Produced from the SGML: /home/isd/public_html/_sql_server_odbc_py/_reml_grp/index.reml
On: 19/3/2004 at 15:34:33
Options: reml2 -i noindex -l long -o html -p multiple