Conversion Errors on Parameters but only on Linux

39 views
Skip to first unread message

cory....@gmail.com

unread,
Jul 11, 2017, 6:36:30 PM7/11/17
to pyodbc
I'm getting parameter conversion errors when updating from version 3.1.1 to 4.0.17 in some environments.....

[HY000] [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0302 - Conversion error on variable or parameter *N. (-302) (SQLExecDirectW)

This appears to be from using a text parameter on a numeric field.

Some example code that would cause this would look like this:
sql_stmt = "SELECT * from ORDERS where order_id = ?"

cursor.execute(sqlstmt, "1")   # Potential failure

cursor.execute(sqlstmt, 1)

This is a web application that I have been using pyodbc in for several years (thanks for a great library).  I would just convert parameters all over my application if the new version requires better typing but I thought I would ask the question of if this is expected before I look at next steps to address.  Here are the environments:

Works - Windows 7 (64bit), Python 3.5.3 (32bit), Pyodbc 3.1.1
Works - Windows 7 (64bit), Python 3.5.3 (32bit), Pyodbc 4.0.17
Works - Linux Debian 9 (64bit), Python 3.5.3 (64bit), Pyodbc 3.1.1
Fails - Linux Debian 9 (64bit), Python 3.5.3 (64bit), Pyodbc 4.0.17

Any thoughts?
Thanks
Cory Lutton

steven...@gmail.com

unread,
Apr 11, 2018, 9:04:01 AM4/11/18
to pyodbc
I don't have a solution, but I'm having the exact same problem! Sounds like I need to look into downgrading pyodbc.

cory....@gmail.com

unread,
Apr 13, 2018, 2:38:41 PM4/13/18
to pyodbc
I solved my issue by reading this: https://github.com/mkleehammer/pyodbc/wiki/Unicode

So for the System i Access driver I basically do this to avoid errors:

    conn = pyodbc.connect(constring)

    # Setup decoding/encoding for this driver.
    conn.setdecoding(pyodbc.SQL_CHAR, encoding='cp1252')
    conn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
    conn.setencoding('utf-8')

Hope it helps.

Cory Lutton
Reply all
Reply to author
Forward
0 new messages