mtadayon / pypyodbc

Automatically exported from code.google.com/p/pypyodbc
0 stars 0 forks source link

Column names are truncated to single character #40

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Connect to database
2. Execute query, e.g.:
>>> cursor.execute("SELECT 1 test")
<pypyodbc.Cursor object at 0x7f84f3e95eb8>
3. Access column names:
>>> cursor.description
[(b't', <class 'int'>, 11, 10, 10, 0, False)]

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

If I use pyodbc, the result is correct:

>>> cursor.execute("select 1 test")
<pyodbc.Cursor object at 0x7f69af0a4db0>
>>> cursor.description
(('test', <class 'int'>, None, 10, 10, 0, False),)

What version of the product are you using? On what operating system?

pypyodbc==1.3.1
Python 3.4.0 (compiled, CFLAGS='-fPIC' ./configure --prefix=/usr/local && make 
&& make install)
Ubuntu 12.04 64bit

Please provide any additional information below.

isql output or pyodbc library gets all column names correctly

Original issue reported on code.google.com by martin.t...@gmail.com on 4 Apr 2014 at 7:46

GoogleCodeExporter commented 9 years ago
I forget to mention, I am connecting to SQL Server 2008 R2

Original comment by martin.t...@gmail.com on 4 Apr 2014 at 7:48

GoogleCodeExporter commented 9 years ago
I'm not able to reproduce this error under my Windows box. 
But is this related to 64bit? Could you find a 32bit and test if problem 
persist?

Original comment by jiangwen...@gmail.com on 24 May 2014 at 2:52

GoogleCodeExporter commented 9 years ago
Same error on my OpenSuse server (32 bit, Python 2.7, unixODBC 2.2.12, FreeTDS 
0.91) - pypyodbc truncates column names to their first chars.
pyodbc works fine - shows full column names.

On Windows 7 32bit, Python 2.6.7 both pypyodbc and pyodbc work fine - with full 
column names.

I've got some inner parms pypyodbc uses:
Linux:   odbc_decoding=utf_16 odbc_encoding=utf_16_le ucs_length=2 
UNICODE_SIZE=4 SQLWCHAR_SIZE=2
Windows: odbc_decoding=utf_16 odbc_encoding=utf_16_le ucs_length=2 
UNICODE_SIZE=2 SQLWCHAR_SIZE=2

Original comment by alex.s.y...@gmail.com on 25 Jun 2014 at 7:45

GoogleCodeExporter commented 9 years ago
I use pypyodbc 1.3.3 from pypi.

Original comment by alex.s.y...@gmail.com on 25 Jun 2014 at 7:49

GoogleCodeExporter commented 9 years ago
Microsoft SQL Server Standard Edition (64-bit) 2008 R2 :-)

Original comment by alex.s.y...@gmail.com on 25 Jun 2014 at 9:32

GoogleCodeExporter commented 9 years ago
Same issue: only the first character for column name by description attribute.
with MS sqlserver 2008 R2 64bit.
unixODBC.i686                     2.2.14-12.el6_3                  @ol6_latest
unixODBC-devel.i686               2.2.14-12.el6_3                  @ol6_latest
freetds.i686                      0.91-2.el6                       @epel
on RHEL6

Python 3.3.1 
pypyodbc (1.3.3)

Original comment by hellowor...@gmail.com on 2 Sep 2014 at 3:47

GoogleCodeExporter commented 9 years ago
I reproduced this problem too. The column names are good on Windows 7, but on 
Linux it does not work.
I use the same Python 3.3.4 on both platforms, the same pypyodbc.
The only difference: ODBC drivers.
On Windows I obviously have the Microsoft ODBC stuff.
On Linux I use the FreeTDS 0.91.103.
So I think pypyodbc/FreeTDS has some problem with SQLServer metadata.
Is there any workaround? Can FreeTDS or pypyodbc be fixed to handle this 
properly?
Any other driver we can use on Linux?

Original comment by leonidil...@yahoo.com on 29 Sep 2014 at 3:09

GoogleCodeExporter commented 9 years ago
I did one more test: downloaded Microsoft ODBC Driver 11 for SQL for RedHat. 
The same problem.
So now I believe that this is not a driver problem, but rather a pypyodbc 
problem in Linux environment.
Any ideas?

Original comment by leonidil...@yahoo.com on 29 Sep 2014 at 4:00

GoogleCodeExporter commented 9 years ago
I found what the problem is, and I have a workaround (or maybe this is the fix).

Apparently, even though the data from the character columns may come as 
unicode, the column names in the descriptor are still plain ascii.

In pypyodbc.py, in _UpdateDesc() method, line 1735, I see:

force_unicode = self.connection.unicode_results

Based on this flag, few lines below, it will call ODBC_APY accordingly. So I 
replaced that line above by:

force_unicode = False

and it fixed the problem.

I am not sure why it works properly on Windows, I cannot see the pypyodbc.py 
code there, I only see pypyodbc-1.3.3-py3.4.egg file which is a binary file.

I hope this is enough information for the maintainers to fix this problem 
properly in the next release.

Original comment by leonidil...@yahoo.com on 29 Sep 2014 at 7:12

GoogleCodeExporter commented 9 years ago
I think issues 43 and 52 are duplicates of this issue.  This problem prevents 
me to use pypyodbc in production.

I also took a quick look at the code, like leonidil... I noted at line 2400

self.unicode_results = False

although one of the arguments is 'unicode_results' and it is used line 2436 to 
establish a connection.  There are 50% chance of discrepancy between 
self.unicode_results and the value used to get a connection.

Original comment by marc.van...@gmail.com on 13 Nov 2014 at 4:02