dailey007 / pyodbc

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

access chinese filename connect? #304

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.how to connect when connect string having chinese?

Original issue reported on code.google.com by south...@gmail.com on 24 Dec 2012 at 7:17

GoogleCodeExporter commented 8 years ago
The connect method is designed to handle Unicode strings, so the problem is 
probably related to the driver's character set settings.

In particular, ODBC is supposed to support ASCII and UCS2, but most drivers do 
not do this correctly.  (I am going to add a charset option to pyodbc to handle 
this...)  Try setting your driver's charset to something UCS2LE compatible and 
see if that helped.

If not, can you provide the OS version, driver and driver version?  Also, an 
ODBC trace would really help.

Original comment by mkleehammer on 28 Mar 2013 at 10:31

GoogleCodeExporter commented 8 years ago
solution:
assume you have a connect string 'connect_str' with chinese characters,the 
following example should work.

import locale, pyodbc
connection = pyodbc.connect(connect_str.decode(locale.getpreferredencoding()))

Original comment by fatcam...@gmail.com on 26 Sep 2014 at 7:26

GoogleCodeExporter commented 8 years ago
or you can try:

import locale, sys
connection = pyodbc.connect(connect_str.decode(sys.getfilesystemencoding()))

Original comment by fatcam...@gmail.com on 26 Sep 2014 at 7:28