mxODBC SQL Type error with MS SQL Server

M.-A. Lemburg mal at lemburg.com
Thu Mar 30 03:57:18 EST 2000


Bill Hunter wrote:
> 
> The mysterious type that mxODBC cannot handle on SQL Server 7 is
> "nvarchar" - unfortunately this is the default that SQL Server
> attempts to use for character strings!
> 
> mxODBC works fine against fields that are not character strings, but
> heck, over half my fields are nvarchar ... true for many other
> people, I conjecture.   Guess I will look at some of the other ODBC
> wrappers that are floating around.
> 
> How big a deal would it be to add a type to mxODBC?  And would it be
> in Python or in C?
> 
> On Wed, 29 Mar 2000 18:47:30 +0530, "George Thom at s"
> <georgethomas at pspl.co.in> wrote:
> 
> >Hi there,
> >I had experienced the same problem ( SQL type (code -9) not implemented
> >) and I reproduce below a fragment from Marc Lehmburg's
> >(mal at lemburg.com)      numerous patient replies to my queries.
> >
> >-------------mal at lemburg.com said -------------------------
> >SQL type -9 is not defined in ODBC 3.5 AFAIK. No idea what
> >type this is. The next version of mxODBC will support
> >unkown types by fetching them as strings, but the current
> >one cannot deal with them, sorry.
> >------------------------------------------------------------
> >
> >Personal Addendum: If you open SQLUCODE.H in the INCLUDE directory of
> >your Visual Studio installation, you will find a line that reads
> >
> >#define SQL_WVARCHAR         (-9)

Ehm, you probably mean "wvarchar" ... I suspect this to be
a wide character VARCHAR field. Adding Unicode to mxODBC is
on the list, but not yet done (have to get the Python
Unicode support rock solid first).

You could try having the ODBC driver convert the type to
a normal string by adding the type to the following switch statement
in mxODBCursor_AllocateOutputVars():

	case SQL_CHAR:
	case SQL_VARCHAR:
	case SQL_WVARCHAR:
	    var->data_len = var->sqllen;
	    /* 0-terminated, so we need to reserve one more byte */
	    var->data_buflen = var->data_len + 1;
	    data = (SQLPOINTER)new(char,var->data_buflen);
	    if (!data) {
		PyErr_NoMemory();
		goto onError;
	    }
	    var->data = data;
	    var->free_data = 1;
	    var->ctype = SQL_C_CHAR;
	    var->convert = &mxODBC_StringFromString;
	    break;

Same for the other possible W+CHAR-type combinations... I
don't know whether the drivers will handle this conversion
correctly and what their output will be though, so you're
on your own here.

BTW, does anyone have a pointer to the specifications
behind the Unicode support in SQL Server or the latest
ODBC variant ?

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/






More information about the Python-list mailing list