[erlang-questions] Erlang ODBC App returns wrong for multi-statement request

Tuan Cao <>
Fri Dec 16 19:45:10 CET 2016


Oops, the previous email was sent when I pasted the source code.

Continue ....

I can't find any detailed information about the issue OTP-5759.

IMHO, the else branch is good enough for this code block. In particular, we
can replace that code block by:

/* Handle multiple result sets */
do {
ei_x_encode_list_header(&dynamic_buffer(state), 1);
msg = encode_result(state);
/* We don't want to continue if an error occured */
if (msg.length != 0) {
break;
}
msg = more_result_sets(state);
/* We don't want to continue if an error occured */
if (msg.length != 0) {
break;
}
} while (exists_more_result_sets(state));
ei_x_encode_empty_list(&dynamic_buffer(state));


I am afraid that doing so will re-surface the issue reported by OTP-5759.
If you have detailed information(for example: bug report, how it was
fixed), please share with me.

Thanks,
Tuan




On Fri, Dec 16, 2016 at 10:33 AM, Tuan Cao <> wrote:

> Hi Erlang community,
>
>
> When running multi-statement request in which the first statement returns
> zero rows, the Erlang ODBC App returns wrong result.
>
> To reproduce:
>
> 1> odbc:start().
>
> ok
>
> 2> {ok, Ref}=odbc:connect("Driver=ODBC Driver 13 for SQL
> Server;Server=XXX;Database=YYY;Uid=ZZZ;Pwd=PPP;Encrypt=
> yes;TrustServerCertificate=no;Connection Timeout=30;", []).
>
> {ok,<0.40.0>}
>
> 3> odbc:sql_query(Ref, "create table z1(i integer);").
>
> {updated,undefined}
>
> 4> odbc:sql_query(Ref, "insert into z1 select * from z1 where 1<0; select
> 1;").
>
> {updated,0}
>
>
> As you can see, odbc_sql_query only returns the first result, and ignore
> all subsequence results.
>
> Looking at the source code, I found that this code block swallow
> subsequence result:
>
>
>
> /* OTP-5759, fails when 0 rows deleted */
> if (result == SQL_NO_DATA_FOUND) {
> msg = encode_result(state);
> } else {
> /* Handle multiple result sets */
> do {
> ei_x_encode_list_header(&dynamic_buffer(state), 1);
> msg = encode_result(state);
> /* We don't want to continue if an error occured */
> if (msg.length != 0) {
> break;
> }
> msg = more_result_sets(state);
> /* We don't want to continue if an error occured */
> if (msg.length != 0) {
> break;
> }
> } while (exists_more_result_sets(state));
> ei_x_encode_empty_list(&dynamic_buffer(state));
> }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161216/1fea6733/attachment.html>


More information about the erlang-questions mailing list