| Issue 219: | pyodbc always returns unicode instead of str | |
| 1 person starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem?
self.cursor.execute("create table t1(s varchar(2048))
self.cursor.execute("insert into t1 values(''XXX")
v = self.cursor.execute("select * from t1").fetchone()[0]
What is the expected output? What do you see instead?
type(v) should return <type 'str'>, but it returns <type 'unicode'>
What version of the product are you using? On what operating system?
MacOS 10.6.7
pyodbc 2.1.8
psqlodbc 09.00.0200
unixodbc 2.2.12
Please provide any additional information below.
I tried to use pyodbc.connect(connection_string, unicode_results=False), but it didn't help.
Oct 27, 2011
Project Member
#1
mkleehammer
Status:
NoFix
Oct 27, 2011
Actually I have noticed in connection.cpp, Connect() - the connection is being established according to the fAsni flag. So if this flag is false, pyODBC is trying to establish a connection using SQLDriverConnectW first - which returns <unicode> results (instead of <str>). If the fAnsi flag is true, OR if the SQLDriverConnectW fails, the connection is being established using SQLDriverConnect - which returns <str> results. The fAnsi flag can be enabled by issuing: pyodbc.connect(connection_string, ansi=1). The problem is that I have also switched from psqlODBC 08.04 to 09.00. In 08.04 SQLDriverConnectW always failed, so pyODBC was automatically switching to SQLDriverConnect. Regarding the trace - I wasn't able to produce it. Can you please assist me on this? |