lexicalunit/nanodbc — pull request #18 by mcg1969 (2014-01-18 23:50:34+00:00)
Title: auto_bind corrections, additional warning suppression

I think this is a bug fix I offered up before, but I got focused on other things and didn't get it done.

First, in auto_bind, the character data needs to be allocated in *SQL* data sizes. So SQL_CHAR needs to be size SQLCHAR, even if you're ultimately going to Unicode, since you're setting col.ctype_ = SQL_C_CHAR. Likewise, for SQL_WCHAR, the size needs to be SQLWCHAR, since col.ctype_ = SQL_C_WCHAR.

The way you had it before, you weren't allocating enough space for SQLWCHAR data, and therefore string data was getting overlaid on top of each other, corrupting the results.

Now, I *think* you could do it another way, if you wanted, and let SQL do all the translation. To do that, you would actually do something like this, I think.

case SQL_CHAR:
case SQL_VARCHAR:
case SQL_WCHAR:
case SQL_WVARCHAR:
#ifdef NANODBC_USE_UNICODE
col.ctype_ = SQL_C_WCHAR;
#else
col.ctype_ = SQL_C_CHAR;
#endif
col.clen_ = ( col.sqlsize_ + 1 ) * sizeof(NANODBC_SQLCHAR);

I don't know this for sure; I haven't tried it! I might though. If I do I'll let you know. The disadvantage here is that you're committing to one string type in your code at compile time. In theory, your current setup, combined with my pull request, lets you mix and match narrow and wide char strings in the same application, as you choose.