Hello all, I'm curious why the odbc module included in PyWin32 (version 214) is compiled without the Unicode flags/defines. This prevents you from using Unicode string literals in queries. By that I mean the Unicode literals are converted to the 8-bit codepage (cp1252) and any untranslatable characters are replaced with ?. Unicode works ok in bind variables, just not as literals in the main query.
That is, unless I set the Unicode flag to True for odbc in PyWin32 setup.py around line 1441. Then the resulting odbc module seems to handle Unicode literals just fine. The test script included below should demonstrate that. The ADO module (adodbapi) doesn't have this issue - Unicode literals work ok. But it suffers from a few other problems, the most basic one is a performance gap of 25-30% compared to ODBC even after I generated the bindings with makepy. I assume this is due to general COM overhead. I can compile my own odbc module with the Unicode flag but I'm curious if there was a reason it was turned off to begin with. Maybe I'm missing something or would run into trouble later if I did that. thanks, -Preston # Note: the goal should be to get "unicode intact" twice. # First time is using a bind variable, second time is a string literal. # This assumes SQL Server backend - string literals are prefixed with N import odbc # Change to suit your server CONNSTR = "dsn/username/password" db = odbc.odbc(CONNSTR) cursor = db.cursor() # This has some extra-wide characters (surrogate pairs) testStr = u"\u0669(\u0361\u0e4f\u032f\u0361\u0e4f)\u06f6 .\U0002a5ab\U0001d122\U00024b00" def query(sql, params): cursor.execute(sql, params) recs = cursor.fetchall() print repr(sql), repr(params) print repr(recs) if recs[0][0] == testStr: print "unicode intact." else: print "unicode did not survive round trip" print return recs # Test as bind variable query1 = "select ? as 'test'" query(query1, [testStr]) # Test as straight Unicode literal query2 = "select N'%s' as 'test'" % (testStr,) query(query2, []) _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32