1

While I'm connecting to HFSQL database to retrieve a set of data using pypyodbc module in python with the following code

import pypyodbc
connection = pypyodbc.connect( "DSN=odbc_name" )
cursor = connection.cursor()
cursor.execute( "select * from cli" )
result = cursor.fetchall()

I get "invalid literal for int() with base 10" error, the source of this problem is the null value of some columns, any workarounds this problem besides modifying the null data in the database table.

rachid el kedmiri
  • 2,376
  • 2
  • 18
  • 40
  • 1
    What line generates the error? – JohanL May 08 '17 at 16:52
  • result = cursor.fetchall() is the line generating the error since I'm using ipython (meaning executing line by line) I'm sure of it. – rachid el kedmiri May 08 '17 at 16:55
  • Isn't the cursor an iterable, allowing you to do something like `for entry in cursor` and then catch, and fix the errors entry by entry? – JohanL May 08 '17 at 16:59
  • as far as I know the process of retrieving data isn't as you said cursor has many methods such as fechone() the difference is the number of rows returned, once you declare a variable result as I did above, you can iterate over it to retrieve the rows one by one – rachid el kedmiri May 08 '17 at 17:14

1 Answers1

0

the solution is to modify pypyodbc.py code located in site-packages directory, the modification is simple look for the methode dt_cvt and modify as follow:

def dt_cvt(x):
if py_v3:
    x = x.decode('ascii')
if x == '': return None
else: return x
rachid el kedmiri
  • 2,376
  • 2
  • 18
  • 40
  • It is not a good idea to monkey patch a package: if a new version is updated you can't upgrade without breaking your old code. I'm pretty sure there is a better way! – Kruupös May 09 '17 at 15:52
  • I agree totaly with you, I will post an issue request on the pypyodbc github, currently I'm tight in time, so I will just hack it to get what i want, all this because of hfsql this RDBMS doesn't follow a well know standard. – rachid el kedmiri May 09 '17 at 20:24