nasihere / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Invalid literal for Decimal #371

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I'm attempting to read a mdb Access database using mdbtools 0.7 and pyodbc 
3.0.7 with the following code:

    import pyodbc

    MDB = 'database.mdb'

    # connect to db
    odbc_connection_str = 'DRIVER={MDBTools};DBQ=%s;' % (MDB,)
    connection = pyodbc.connect(odbc_connection_str)
    cursor = connection.cursor()

    SQL = 'SELECT * FROM mytable'
    rows = cursor.execute(SQL).fetchall()

    for row in rows:
        print row

However, this throws the exception:

    Traceback (most recent call last):
      File "test.py", line 26, in <module>
        rows = cursor.execute(SQL).fetchall()
      File "/usr/lib/python2.7/decimal.py", line 548, in __new__
        "Invalid literal for Decimal: %r" % value)
      File "/usr/lib/python2.7/decimal.py", line 3866, in _raise_error
        raise error(explanation)
    decimal.InvalidOperation: Invalid literal for Decimal: u''

Presumably, pyodbc is attempting to interpret a null decimal column value, 
being returned as u'', as a non-null value. A u'' value should be interpreted 
as the Python `None`, not throw an exception.

Original issue reported on code.google.com by chrisspen@gmail.com on 17 Jun 2014 at 6:38