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

Ingela Andin <>
Fri Dec 9 15:05:35 CET 2011


Hi!

Sound like a problem in the odbc-driver (if I remember correctly iodbc
is the name of the most common driver on MAC)  sql_wvarchar is defined
to be Unicode encoded as UTF16 little endian.

Regards Ingela Erlang/OTP team - Ericsson AB



2011/12/1, Chad Phillips -- Apartment Lines <>:
> 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:
>
> ()1> odbc:start().
> ok
> ()2> {ok, Ref} = odbc:connect("DSN=testing;Option=3", []).
> {ok,<0.90.0>}
> ()3> odbc:describe_table(Ref, "foo").
> {ok,[{"bar",{sql_wvarchar,255}}]}
> ()4> odbc:select_count(Ref, "SELECT * FROM foo").
> {ok,1}
> ()5> {selected, Columns, [{Bar}]} = odbc:next(Ref).
> {selected,["bar"],[{<<98,0,97,0,122,0>>}]}
> ()6> unicode:characters_to_list(Bar, {utf16, little}).
> "baz"
> ()7> unicode:characters_to_list(Bar, {utf32, little}).
> {error,[],<<98,0,97,0,122,0>>}
>
> OS X ERLANG SESSION:
>
> ()1> odbc:start().
> ok
> ()2> {ok, Ref} = odbc:connect("DSN=testing;Option=3", []).
> {ok,<0.90.0>}
> ()3> odbc:describe_table(Ref, "foo").
> {ok,[{"bar",{sql_wvarchar,255}}]}
> ()4> odbc:select_count(Ref, "SELECT * FROM foo").
> {ok,1}
> ()5> {selected, Columns, [{Bar}]} = odbc:next(Ref).
> {selected,["bar"],[{<<98,0,0,0,97,0,0,0,122,0,0,0>>}]}
> ()6> unicode:characters_to_list(Bar, {utf16, little}).
> [98,0,97,0,122,0]
> ()7> unicode:characters_to_list(Bar, {utf32, little}).
> "baz"
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list