Access 97 Dates using ODBC

Robin Munn rmunn at pobox.com
Fri Feb 28 19:54:15 CET 2003


Cy Edmunds <cedmunds at spamless.rochester.rr.com> wrote:
> Consider the following code:
> 
> import dbi, odbc
> import time
> 
> dbc = odbc.odbc('sample')
> crsr = dbc.cursor()
> crsr.execute('SELECT insert_change_date FROM country')
> result = crsr.fetchone()
> print str(result[0])
> 
> Using Access 2000 it prints out:
> 
> Wed Feb 12 00:00:00 1997
> 
> which is in fact what is stored in the database. However with
> Access 97 it raises an exception. (The exact wording of the
> exception I can't recall -- this happens at work and I am now
> at home. But the gist of it is that the object doesn't support
> the str() operation.)
> 
> Has anybody seen this problem before? Do you have a
> workaround?

I've never dealt with this problem before and so cannot suggest a
workaround, but I can suggest an approach to get some more information,
which might lead to figuring out a workaround. Try printing the type of
the returned object, and its class (if it has one):

    import dbi, odbc
    import time

    dbc = odbc.odbc('sample')
    crsr = dbc.cursor()
    crsr.execute('SELECT insert_change_date FROM country')
    result = crsr.fetchone()
    print type(result[0])
    try:
        print result[0].__class__
    except AttributeError:
        print "Not a class instance"
    print str(result[0])

Depending on what type of object is being returned, this may help.

Also, you might consider using Marc-André Lemburg's mxODBC package. It's
free for non-commercial use (which I believe would include open-source
development, although you'd have to ask Marc-André to be certain). It
uses mxDateTime objects for returning dates, which might take care of
the problem you're encoutering.

Let us know what you find out.

-- 
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838    50FF 2478 CFFB 081A 8338  54F7 845D ACFD 6AFB 6838




More information about the Python-list mailing list