| Issue 136: | Retrieving XML data from SQL Server via FreeTDS yields a bus error | |
| 1 person starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem?
1. Use pyodbc to access a SQL Server database which has a table <tbl> which contains a column <col> which has the xml datatype.
2. c.execute("select top 1 <col> from <tbl> where <col> is not null")
3. c.fetchall()
What is the expected output? What do you see instead?
I expect to see the contents of the field. Instead, I get a bus error.
What version of the product are you using? On what operating system?
pyodbc 2.1.8
MacOS X 10.6.4
Python 2.6
Please provide any additional information below.
FreeTDS CVS checkout from 11/16/2010
iODBC driver manager
SQL Server 2008 RTM
gdb tells me that the bus error is
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000004
0x0038fabf in GetDataString (cur=0x7028e0, iCol=<value temporarily unavailable, due to optimizations>) at pyodbc-2.1.8/src/getdata.cpp:194
194 if (PyString_CheckExact(bufferOwner))
I suspect that this is related to issue 97 . My value for sys.maxunicode:
65535
For what it's worth, the minimum datalength in the table I'm accessing is 1826.
Nov 20, 2010
Project Member
#1
mkleehammer
Labels:
OpSys-OSX
Sep 29, 2012
Just an update: FreeTDS 0.91 always returns the same length for XML data, so it is impossible to know the real length. It seems to return the maxtext value, which in my case is 2147483647. It happens to work when the XML length <= 1023 bytes because pyodbc uses a 1024 byte stack buffer. If the value is larger, it needs to allocate memory based on the size the driver reports. I'm digging through the FreeTDS source, but I don't see a quick fix yet.
Status:
Investigating
Sep 29, 2012
(No comment was entered for this change.)
Labels:
-OpSys-OSX Driver-freetds
Sep 29, 2012
My previous comment was incorrect. The length is not always the same. Using FreeTDS 0.91 and pyodbc 3.0.6+, the problem is that a NULL terminator sometimes overwites the last byte. Still working on it.
Sep 29, 2012
I've raised two issues on the FreeTDS mailing list: 1) FreeTDS reports the column as SQL_CHAR instead of SQL_SS_XML 2) SQLGetData always returns SQL_SUCCESS, even if the buffer size is too small. This means pyodbc 3.0.6+ is going to return XML as ANSI text and will work as long as the text is less than 1024 characters (the internal buffer size used for the first select). In the meantime, you might consider using the Microsoft SQL Server Driver for Linux. It works extremely well.
Status:
Hold
|