rajeshveerepalli / pyodbc

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

the error message is not unicode on chinese system? #62

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
i try to excute a error sql statement.
the error raised by pyodbc on chiese Windows system is not unicode.
i use this function to decode the message to chinese.

def decodeErrorMessage(e):
    s = repr(e)
    s = s.replace("'","\\'")
    s = s.replace('"',"\\\"")
    s = eval('"'+s+'"')

    return s.decode('gbk').encode('utf-8')

is that a problem of pyodbc?

the message return by pyodbc when i try to connect to MS SqlServer 2008
Chinese Edition.

ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server
Driver][SQL Ser
ver]\xce\xde\xb7\xa8\xb4\xf2\xbf\xaa\xb5\xc7\xc2\xbc\xcb\xf9\xc7\xeb\xc7\xf3\xb5
\xc4\xca\xfd\xbe\xdd\xbf\xe2
"iSatServerDB"\xa1\xa3\xb5\xc7\xc2\xbc\xca\xa7\xb0\
xdc\xa1\xa3 (4060) (SQLDriverConnectW); [42000] [Microsoft][ODBC SQL Server
Driv
er][SQL
Server]\xce\xde\xb7\xa8\xb4\xf2\xbf\xaa\xb5\xc7\xc2\xbc\xcb\xf9\xc7\xeb\
xc7\xf3\xb5\xc4\xca\xfd\xbe\xdd\xbf\xe2
"iSatServerDB"\xa1\xa3\xb5\xc7\xc2\xbc\x
ca\xa7\xb0\xdc\xa1\xa3 (4060)')

Original issue reported on code.google.com by wangle...@gmail.com on 14 Jul 2009 at 12:26

GoogleCodeExporter commented 8 years ago

Original comment by mkleehammer on 15 Jul 2009 at 1:58

GoogleCodeExporter commented 8 years ago
All exceptions in Python 2.x use ANSI strings so pyodbc does also.  I'm 
currently 
using the ANSI version of SQLGetDiagRec to retreive the error.

The Python 3.x version will obviously use Unicode for everything, so that'll 
help.

In the meantime, I'm not exactly sure what the best approach is.  There is a 
connect 
keyword unicode_results that forces all retrieved strings to be converted to 
Unicode.  This is sort-of a stopgap Unicode feature until the 3.x version is 
released.  If you really need Unicode errors, I guess I could add a 
unicode_errors 
keyword that would force errors to be returned in Unicode.  Is that something 
you 
are interested in?

(Also note that I can't promise it will work -- I'm using the Python C 
interface and 
until I try it I'm not entirely sure passing Unicode values to the constructor 
will 
work.  I think so, though.)

Original comment by mkleehammer on 8 Aug 2009 at 2:45