[unixODBC-support] How driver manager converts between Unicode and ANSI

Daniel Vogelbacher daniel at vogelbacher.name
Thu Apr 11 17:32:48 BST 2013


as far as I understand the official ODBC spec, the DM must convert
between wide-strings and ansi-strings. On Windows this is done by
converting from unicode to the current code page (locale setting) and
vice versa.
For example, if I use a ANSI-only driver and call SQLExecDirectW(),
the unicode string gets converted to my local code page (iso8859-1 or
something else) and passed to driver's SQLExecDirect().

In real world, I discoverd two issues:
 1.) Most drivers ANSI functions expecting strings not in code page
 encoding, but in a driver-specifc encoding, for example a character
 set specified inside the DSN (like CharSet=utf8).
 If a user loads a ansi-only driver which expects string in encoding
 XY, how does the DM knows about that to perform the correct
 conversion between unicode and XY? (this is more a windows issue, but
 related to the next issue)

 2.) The DM from unixODBC seems to do something totally curious when
 converting between unicode and ansi. I expected that it uses
 mbstowcs() & co. for conversion regarding the locale setting
 (en_US.utf8 or something else).
 But a lot of tests and a final look into the code later I discovered
 that the DM just choose iso8859-1... ?!
 This breaks the usage of the wide-api on application side and a
 ansi-only driver (like sqliteodbc) which expects UTF-8 strings.
 Is this really intended?

 But even if the DM uses the locale information (how I expected),
 there is issue no. 1 for drivers which are expecting a specific
 charset (like the sqlite odbc driver).

I hope someone could help me with this. It's very confusing.

     Daniel Vogelbacher
     cytrinox at freenode/ircnet/quakenet

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-support/attachments/20130411/51ffe392/attachment.bin>

More information about the unixODBC-support mailing list