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

Tuan Cao <>
Fri Dec 16 19:33:25 CET 2016


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/65fc6f66/attachment.html>


More information about the erlang-questions mailing list