[erlang-questions] ODBC to Erlang data mapping problem on OS X

Chad Phillips -- Apartment Lines chad@REDACTED
Thu Dec 1 17:17:13 CET 2011


According to http://www.erlang.org/doc/apps/odbc/databases.html#type, the SQL_WVARCHAR ODBC data type should be translated by  Erlang's ODBC driver to "Unicode binary encoded as UTF16 little endian."

This works as expected on Linux, but I'm having issues on OS X, where it appears it's getting translated to UTF32 little endian, instead of UTF16 little endian.

I'm using Erlang R14B04 on both machines, with the exact same database table, does anybody have an idea why this might be occurring, and how to remedy it?

Additional info below for those interested.

Thanks!

Chad

TABLE ON BOTH ARCHITECTURES:

CREATE TABLE `foo` (
  `bar` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


LINUX ERLANG SESSION:

(alaem@REDACTED)1> odbc:start().
ok
(alaem@REDACTED)2> {ok, Ref} = odbc:connect("DSN=testing;Option=3", []).
{ok,<0.90.0>}
(alaem@REDACTED)3> odbc:describe_table(Ref, "foo").
{ok,[{"bar",{sql_wvarchar,255}}]}
(alaem@REDACTED)4> odbc:select_count(Ref, "SELECT * FROM foo").
{ok,1}
(alaem@REDACTED)5> {selected, Columns, [{Bar}]} = odbc:next(Ref).
{selected,["bar"],[{<<98,0,97,0,122,0>>}]}
(alaem@REDACTED)6> unicode:characters_to_list(Bar, {utf16, little}).
"baz"
(alaem@REDACTED)7> unicode:characters_to_list(Bar, {utf32, little}).
{error,[],<<98,0,97,0,122,0>>}

OS X ERLANG SESSION:

(alaem@REDACTED)1> odbc:start().
ok
(alaem@REDACTED)2> {ok, Ref} = odbc:connect("DSN=testing;Option=3", []).
{ok,<0.90.0>}
(alaem@REDACTED)3> odbc:describe_table(Ref, "foo").
{ok,[{"bar",{sql_wvarchar,255}}]}
(alaem@REDACTED)4> odbc:select_count(Ref, "SELECT * FROM foo").
{ok,1}
(alaem@REDACTED)5> {selected, Columns, [{Bar}]} = odbc:next(Ref).
{selected,["bar"],[{<<98,0,0,0,97,0,0,0,122,0,0,0>>}]}
(alaem@REDACTED)6> unicode:characters_to_list(Bar, {utf16, little}).
[98,0,97,0,122,0]
(alaem@REDACTED)7> unicode:characters_to_list(Bar, {utf32, little}).
"baz"


More information about the erlang-questions mailing list