[erlang-patches] PATCH: ODBC application discarding sqlstate in get_diagnos function

Juhani Ränkimies <>
Sat Oct 10 09:30:48 CEST 2009


I've had similar problems on windows with mssql2008. The behaviour
wasn't identical, but with luck your patch fixes it in my setup too.

I'll definitely have a look. It'll take a while though, as setting up
a build env in windows is laborious and I've got my hands full
already.

Thanks,
-juhani


On Fri, Oct 9, 2009 at 8:47 PM, Andrew Thompson <> wrote:
> Hi,
>
> I've been using the ODBC application against a unixodbc/mysql setup for
> a while now and its been bothering me that ANY SQL error always returns
> {port_exit,could_not_access_column_count} from the erlang side. I
> decided to dig into the code and figure out why and this is what I
> discovered:
>
> In the get_diagnos function of odbcserver.c every time SQLGetDiagRec is
> called diagnos.sqlState is passed in as the target to write the returned
> SQLSTATE into. However, when you've run out of diagnostic information
> and SQLGetDiagRec() returns something other than SQL_SUCCESS, the value
> of diagnos.sqlState *still* gets changed (at least in my case) to 00000,
> which is, of course, the INFO SQLSTATE. This causes the check in
> db_query against INFO to succeed when it should be failing and since in
> my case the error message didn't begin with 'error' it falls through
> encode_result which is where the EXIT_COLS comes in. Attached is a patch
> to resolve this problem by only updating diagnos.sqlState when
> SQLGetDiagRec returns success.
>
> I don't know if all ODBC implementations behave this way, but I'd assume
> that the SQLSTATE from a failed SQLGetDiagRec can safely be ignored in
> all cases.
>
> Thanks,
>
> Andrew
>
>
> ________________________________________________________________
> erlang-patches mailing list. See http://www.erlang.org/faq.html
> erlang-patches (at) erlang.org


More information about the erlang-patches mailing list