[egenix-users] Problem with cursor.information

M.-A. Lemburg mal at egenix.com
Wed Aug 17 12:40:44 CEST 2005


M.-A. Lemburg wrote:
> Bernhard Snizek wrote:
> 
>>Hi,
>>
>> I am currently evaluating mxODBC for a medium size database 
>>integration project where I use Z3.
>>
>>I want to connect to an Access .mdb file via mdbtools <-> unixODBC <- >
>>mxODBC.unixODBC <-> Zope3 [freeBSD]
>>
>>Everything works fine, I can establish a connection and even fetch 
>>records BUT cursor.information contains only tuples where the column  id
>>is empty.
>>
>>
>>>>>import mx
>>>>>import mx.ODBC
>>>>>import mx.ODBC.unixODBC
>>>>>mx.ODBC.unixODBC.DriverConnect('DSN=myDSN')
>>>>>dc = dn.cursor()
>>>>>dc.execute('select * from kvarter')
>>>>>dc.fetchone()
>>
>>(50, 'Br\xf8nsh\xf8j')
>>
>>>>>dc.description
>>
>>(('', 4, None, None, 4, 0, 0), ('', 12, None, None, 100, 0, 1))
>>
>>I changed my setup to an iODBC connection, the result is the same, 
>>empty column id's.
>>
>>When I open the DSN by using isql and execute the same sql statement  as
>>above it returns the column ids properly:
> 
> 
> mxODBC uses SQLDescribeCol() to fetch the column name, isql uses
> SQLColAttribute(). Both are mapped to a function in the ODBC
> driver, so it looks as if the mdbtools ODBC doesn't work
> correctly with SQLDescribeCol() and returns empty strings
> instead of the true column name.

Here's the snippet from the mdbtools driver:

SQLRETURN SQL_API SQLDescribeCol(
    SQLHSTMT           hstmt,
    SQLUSMALLINT       icol,
    SQLCHAR FAR       *szColName,
    SQLSMALLINT        cbColNameMax,
    SQLSMALLINT FAR   *pcbColName,
    SQLSMALLINT FAR   *pfSqlType,
    SQLUINTEGER FAR   *pcbColDef, /* precision */
    SQLSMALLINT FAR   *pibScale,
    SQLSMALLINT FAR   *pfNullable)
{
...
	if (szColName) {
		namelen = MIN(cbColNameMax,strlen(sqlcol->name));
		strncpy(szColName, sqlcol->name, namelen);
		szColName[namelen]='\0';
	}
...

and the ODBC specs for the above API:

http://msdn.microsoft.com/library/en-us/odbc/htm/odbcsqldescribecol.asp

As you can see, the driver forgets to update *pcbColName
(NameLengthPtr in the ODBC docs - not sure where mdbtools
got the strange name from) to the value namelen.

Since mxODBC initialized this buffer to 0, it thinks that
the string length is 0 and thus returns an empty string.

SQLColAttributes() in mdbtools has the same problem, BTW.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Aug 17 2005)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the egenix-users mailing list