Discussion:
Basic ODBC question
(too old to reply)
Maury Markowitz
2012-06-20 13:37:22 UTC
Permalink
I know there is an ODBC subgroup, but it's inhabited solely by spam,
so I hope it's OK if I post here. This has nothing to do with
SQLServer, and takes place on the Mac using iODBC. However, I can't
find any mailing list or group that's suitable, and I suspect people
in this group will have some knowledge...

I'm writing an ODBC application using iODBC, and I'm using a small DB
running under MySQL to test against. The data contains some Unicode,
which my character conversion routines "drop" during conversion. I end
up with strings with "holes" in them. In other cases, certain
characters within the columns or names confuse things further.

So, my question is how do I know if the data in a column is in
Unicode, 7-bit ASCII, 8-bit, ShiftJIS, or something else? I know how
to properly convert all of these, but I don't know how to tell if I
need to.

SQLDescribeCol would seem to be the place to go. But when I look in
sqltypes.h, I see references to Unicode and SQLWCHAR, but I'm
mystified how one uses them in practice.
Erland Sommarskog
2012-06-20 19:19:27 UTC
Permalink
Post by Maury Markowitz
I know there is an ODBC subgroup, but it's inhabited solely by spam,
so I hope it's OK if I post here. This has nothing to do with
SQLServer, and takes place on the Mac using iODBC. However, I can't
find any mailing list or group that's suitable, and I suspect people
in this group will have some knowledge...
I'm writing an ODBC application using iODBC, and I'm using a small DB
running under MySQL to test against. The data contains some Unicode,
which my character conversion routines "drop" during conversion. I end
up with strings with "holes" in them. In other cases, certain
characters within the columns or names confuse things further.
So, my question is how do I know if the data in a column is in
Unicode, 7-bit ASCII, 8-bit, ShiftJIS, or something else? I know how
to properly convert all of these, but I don't know how to tell if I
need to.
SQLDescribeCol would seem to be the place to go. But when I look in
sqltypes.h, I see references to Unicode and SQLWCHAR, but I'm
mystified how one uses them in practice.
Since may be specific to the driver or DBMS you are using, I am afraid
that this is not the best place to ask.

I guess that if the target column is nvarchar (or what it might be
called on MySQL) and the source data is Unicode UTF-16, SQLWCHAR is the
right choice. But then again, your data may be UTF-8, and that also
may be how MySQL handles Unicode.

If you try a MySQL forum, you at least have that part covered.
--
Erland Sommarskog, SQL Server MVP, ***@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
Continue reading on narkive:
Loading...