[erlang-questions] MySQL and Erlang: ODBC , column type error

Carl McDade carlmcdade@REDACTED
Mon May 11 16:20:37 CEST 2009


On Mon, May 11, 2009 at 4:19 PM, Carl McDade <carlmcdade@REDACTED> wrote:
Well, MySQL only allows CONVERT to certain types. The relavent one
here being CHAR. But Erlang does not accept this either. VARCHAR is a
basic in MySQL but Erlang refuses this data type even when I forced
the database into ANSI only mode. But it works fine when using DECIMAL
or CONVERT to DECIMAL.

Weird.

8> odbc:sql_query(Conn, "SELECT {fn CONVERT(option_name, CHAR)} FROM
wp_options").
{error,"Column type not supported"}
9> odbc:sql_query(Conn, "SELECT {fn CONVERT(option_name,VARCHAR)} FROM
wp_options").
{error,"[MySQL][ODBC 5.1 Driver][mysqld-5.1.32-community-log]You have
an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'VARCHAR)} FROM
wp_options' at line 1 SQLSTATE IS: 42000"}
10> odbc:sql_query(Conn, "SELECT {fn CONVERT(option_name,
SQL_VARCHAR)} FROM wp_options").
{error,"[MySQL][ODBC 5.1 Driver][mysqld-5.1.32-community-log]You have
an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'SQL_VARCHAR)}
FROM wp_options' at line 1 SQLSTATE IS: 42000"}
11> odbc:sql_query(Conn, "SELECT {fn CONVERT(option_name, DECIMAL)}
FROM wp_options").
{selected,["{fn CONVERT(option_name, DECIMAL)}"],
         [{0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {0.0},
          {...}|...]}
12>
> On Mon, May 11, 2009 at 4:03 PM, Robert Raschke <rtrlists@REDACTED> wrote:
>>
>> On Mon, May 11, 2009 at 2:44 PM, Carl McDade <carlmcdade@REDACTED> wrote:
>>>
>>> [...]
>>>
>>> Out of this list there are 8 varchar fields of varying lengths that
>>> should be supported as strings according to the ODBC to Erlang map in
>>> the docs.
>>>
>>
>> These days, those varchar strings are actually very likely to be nvarchar
>> fields (what does MySQL actually say those columns are?) and therefore not
>> supported by Erlang odbc. Have you tried using ODBC conversion functions to
>> recast your SQL results, as I suggested?
>>
>> Unless you're trying to write some kind of DB agnostic
>> higher-level-do-anything-kind-of-thingamajig (ORM?), and you want to get a
>> bit of data in and out of the DB, I suggest just casting your values. It's
>> easier than any other approach.
>>
>> Robby
>>
>>
>
>
>
> --
> Carl McDade
> Content Management Systems Consultant
> www.hiveminds.co.uk
> ________________________
>



-- 
Carl McDade
Content Management Systems Consultant
www.hiveminds.co.uk
________________________



More information about the erlang-questions mailing list