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

Tuan Cao tuanbeo0502@REDACTED
Thu Dec 29 04:37:23 CET 2016


I am sorry if this is a duplicated post.

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));
}
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161229/069dd5d9/attachment.htm>


More information about the erlang-questions mailing list