tanrj / pyodbc

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

Select with empty 'text' field causes MemoryError when unicode_strings=True on Ubuntu/FreeTDS/iODBC #97

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. conn=connect('...', unicode_strings=True)
2. c = conn.execute('SELECT TOP 1 text_field FROM aTable')
   print c.fetchone() # where text_field is NULL

What is the expected output? What do you see instead?
Expected 'None' or empty string. Causes MemoryError exception where
unicode_strings=True

What version of the product are you using? On what operating system?
pyODBC 2.1.7, Ubuntu 9.04+, FreeTDS/tdsodbc 0.82-14 shipped with Ubuntu
python 2.5.x, 2.6.2

Please provide any additional information below.
Looks like some conversion error. Executing 'select DATALENGTH(text_field)'
returns 'None'

Original issue reported on code.google.com by av1024@gmail.com on 13 Apr 2010 at 11:56

GoogleCodeExporter commented 8 years ago
The Unicode handling has been revamped in the Python 3.x line, and I think I 
need to bring it over to the 2.x 
line.

For reference, can you tell me the value of sys.maxunicode on your build:

  import sys
  print sys.maxunicode

I suspect it is UCS4, which for some reason, has become a very popular 
configuration in the Linux distros.

Also, if I can't reproduce this, can I give you a custom pyd (DLL) to try?

Original comment by mkleehammer on 16 Apr 2010 at 6:28

GoogleCodeExporter commented 8 years ago
Another thing I noticed, the value you want is "unicode_results", not 
"unicode_strings".

(I know this seems error prone, but lots of people like to use keywords to pass 
the DSN values and it is a DB API 
standard, so I allow it.  If I don't recognize the keyword, it simply gets 
added to the DSN.)

Can you confirm which you were using?

Original comment by mkleehammer on 16 Apr 2010 at 6:37

GoogleCodeExporter commented 8 years ago
The sys.maxunicode == 1114111 == 0x10FFFF.
On my (other) win64 machine maxunicode==65535.

Of course, "unicode_results".

Yes, I will try your custom pyd.

Original comment by av1024@gmail.com on 18 Apr 2010 at 10:00

GoogleCodeExporter commented 8 years ago
I've also encountered this error, except the type I've encountered it on is 
nvarchar and it doesn't matter what unicode_results is.

My configuration:

pyodbc 2.1.8
FreeTDS CVS checkout from 11/16/2010
MacOS X 10.6.4
Python 2.6
iODBC driver manager
SQL Server 2008 RTM

I get the same behavior as the reporter with 'select DATALENGTH...' on the 
relevant column.

sys.maxunicode = 65535

Original comment by s...@mitre.org on 17 Nov 2010 at 4:32

GoogleCodeExporter commented 8 years ago
I'm closing this because I believe it is fixed in the 3.0.x builds.  Also, 
Microsoft now has a Linux driver which definitely works.

Original comment by mkleehammer on 27 Dec 2011 at 1:03

GoogleCodeExporter commented 8 years ago
Still encountering this issue on OS/X.  iODBC and FreeTDS.

Original comment by gsib...@gmail.com on 9 Oct 2013 at 3:21