Loprz / pypyodbc

Automatically exported from code.google.com/p/pypyodbc
0 stars 0 forks source link

"invalid literal" exceptions querying empty numeric fields when using LinuxODBC with FreeTDS #48

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Setup a linux system running pypyodbc using LinuxODBC and FreeTDS to access 
a MSSQL database
2. Query any table that contains entries with empty numeric fields

What is the expected output? What do you see instead?
Instead of getting a valid response, depending on the field type, one of the 
following two exceptions will be thrown:
invalid literal for int() with base 10: ''
Invalid literal for Decimal: ''

The issue appears to be that FreeTDS returns empty fields as '' which the stock 
python conversion functions throw an exception on while converting.

What version of the product are you using? On what operating system?
pypyodbc 1.3.3
python 2.6
linux

Please provide any additional information below.

We solved this by:
1. editing the Decimal_cvt() function to return None if x = "" 
2. Adding other conversion functions int_cvt(), long_cvt(), and float_cvt()
3.  editing editing the SQL_data_type_dict to use the new conversion functions 
instead of the stock python int, float, and long functions

See the attached edited version of pypyodbc.py version 1.3.3 for all of the 
changes that were made.

Original issue reported on code.google.com by rmcn...@gmail.com on 12 Aug 2014 at 4:40

Attachments: