My favorites | Sign in
Project Home Downloads Wiki
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 371: Invalid literal for Decimal
6 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----


 
Reported by chrisspen@gmail.com, Jun 17, 2014
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.

Powered by Google Project Hosting