methew / pyodbc

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

UnicodeDecodeError in cursor.execute on specific column names #355

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
import pyodbc
db=pyodbc.connect('DSN=Veramtex_tst')
cur=db.cursor()
cur.execute('select cdno from contacts')
<pyodbc.Cursor object at 0x02B8EFA8>
cur.execute("select cdno as 'é' from contacts")
Traceback (innermost last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 0: 
unexpected end of data
cur.execute("select 'é' as e from contacts")
<pyodbc.Cursor object at 0x02B8EFA8>

What is the expected output? What do you see instead?

The second query should work the same way as the first one.  Instead, I got a 
UnicodeDecodeError As the third query works well, I strongly suspect that 
pyodbc has problems on non ASCII column names.  

What version of the product are you using? On what operating system?
Python 3.3.3
pyodbc 3.0.7
dabatabase: MySQL 5.5.34

Please provide any additional information below.

Original issue reported on code.google.com by marc.van...@gmail.com on 20 Jan 2014 at 3:34

GoogleCodeExporter commented 9 years ago
This problem does not exists using Python 2.7.6 and the same other components:
stmt='select cdno from contacts'
cur.execute(stmt)
<pyodbc.Cursor object at 0x06688DE8>
stmt='select cdno as "é" from contacts'
cur.execute(stmt)
<pyodbc.Cursor object at 0x06688DE8>

Original comment by marc.van...@gmail.com on 20 Jan 2014 at 4:48

GoogleCodeExporter commented 9 years ago

Original comment by mich...@kleehammer.com on 3 Feb 2014 at 1:07

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I have the same problem:

conexionDSNnavision = pyodbc.connect(DSN=config.DSNnavision, autocommit=True, 
ansi=True, readonly=True, unicode_results=True)
cursorDSNnavision = conexionDSNnavision.cursor()
query = "SELECT  Nº,Nombre FROM Cliente 
cursorDSNnavision.execute(query)

Error:
cursorDSNnavision.execute(query)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xba in position 1: invalid 
start byte

but I do this:

conexionDSNnavision = pyodbc.connect(DSN=config.DSNnavision, autocommit=True, 
ansi=True, readonly=True, unicode_results=True)
cursorDSNnavision = conexionDSNnavision.cursor()
query = "SELECT  Nº FROM Cliente 
cursorDSNnavision.execute(query)

works perfectly, what's happening?

Original comment by agar...@empretal.com on 28 Feb 2014 at 1:26

GoogleCodeExporter commented 9 years ago
Workaround:
Executoing the following instruction:
db.execute("SET @@character_set_results = 'latin1'")
before issuing the SELECT statement,
everything works well.  
Question now is why is it necessary to do that and how can I know which 
character set to use?

Original comment by marc.van...@gmail.com on 3 Mar 2014 at 10:34