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

Chad Phillips -- Apartment Lines <>
Sun Dec 11 07:52:00 CET 2011


Found the problem.  It's a bug in the configure scripts located in lib/odbc of the Erlang source code, which hard code '-liodbc' when $host_os is darwin -- this prevents anyone from being able to properly link against a unixODBC install on OS X, which needs '-lodbc' instead.

In my case, via MacPorts, this apparently meant it was using the MacPorts unixODBC headers, but linking against the default OS X iODBC lib, which I'm guessing is what led to the weird behavior I was seeing.

I've created a patch for the MacPorts version of Erlang, but I'm pretty autoconf clueless, so all it does is hard code '-lodbc' in place of '-liodbc', which is clearly not the right upstream solution.  ;)

If there's anything else I can do to help fix this bug, please let me know.

Thanks,

Chad

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-lib_odbc_configure
Type: application/octet-stream
Size: 1847 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111210/de49cb68/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch-lib_odbc_configure.in
Type: application/octet-stream
Size: 529 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111210/de49cb68/attachment-0001.obj>
-------------- next part --------------



On Dec 9, 2011, at 6:05 AM, Ingela Andin wrote:

> 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