<div dir="ltr">Hi Erlang community,<div><br></div><div><br></div><div>When running multi-statement request in which the first statement returns zero rows, the Erlang ODBC App returns wrong result.</div><div><br></div><div>To reproduce:</div><div>







<p class="gmail-p1"><span class="gmail-s1">1> odbc:start().</span></p>
<p class="gmail-p1"><span class="gmail-s1">ok</span></p>
<p class="gmail-p1"><span class="gmail-s1">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;", []).</span></p>
<p class="gmail-p1"><span class="gmail-s1">{ok,<0.40.0>}</span></p>
<p class="gmail-p1"><span class="gmail-s1">3> odbc:sql_query(Ref, "create table z1(i integer);").</span></p>
<p class="gmail-p1"><span class="gmail-s1">{updated,undefined}</span></p>
<p class="gmail-p1"><span class="gmail-s1">4> odbc:sql_query(Ref, "insert into z1 select * from z1 where 1<0; select 1;").</span></p>
<p class="gmail-p1"><span class="gmail-s1">{updated,0}</span></p><p class="gmail-p1"><span class="gmail-s1"><br></span></p><p class="gmail-p1"><span class="gmail-s1">As you can see, odbc_sql_query only returns the first result, and ignore all subsequence results.</span></p><p class="gmail-p1"><span class="gmail-s1">Looking at the source code, I found that this code block swallow subsequence result:</span></p><p class="gmail-p1"><span class="gmail-s1"><br></span></p><p class="gmail-p1"><span class="gmail-s1"></span></p><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container" style="box-sizing:border-box;border-collapse:collapse;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,"segoe ui",helvetica,arial,sans-serif,"apple color emoji","segoe ui emoji","segoe ui symbol";font-size:14px"><tbody style="box-sizing:border-box"><tr style="box-sizing:border-box"><td id="gmail-LC661" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre"><br class="gmail-Apple-interchange-newline">    <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">/* OTP-5759, fails when 0 rows deleted */</span></td></tr><tr style="box-sizing:border-box"><td id="gmail-L662" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC662" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">  <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> (result == SQL_NO_DATA_FOUND) {</td></tr><tr style="box-sizing:border-box"><td id="gmail-L663" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC663" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">        msg = <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">encode_result</span>(state);</td></tr><tr style="box-sizing:border-box"><td id="gmail-L664" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC664" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">    } <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">else</span> {</td></tr><tr style="box-sizing:border-box"><td id="gmail-L665" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC665" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">      <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">/* Handle multiple result sets */</span></td></tr><tr style="box-sizing:border-box"><td id="gmail-L666" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC666" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">        <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">do</span> {</td></tr><tr style="box-sizing:border-box"><td id="gmail-L667" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC667" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">           <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">ei_x_encode_list_header</span>(&<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">dynamic_buffer</span>(state), <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">1</span>);</td></tr><tr style="box-sizing:border-box"><td id="gmail-L668" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC668" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">           msg = <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">encode_result</span>(state);</td></tr><tr style="box-sizing:border-box"><td id="gmail-L669" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC669" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">       <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">/* We don't want to continue if an error occured */</span></td></tr><tr style="box-sizing:border-box"><td id="gmail-L670" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC670" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">          <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> (msg.<span class="gmail-pl-smi" style="box-sizing:border-box">length</span> != <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">0</span>) { </td></tr><tr style="box-sizing:border-box"><td id="gmail-L671" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC671" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">            <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">break</span>;</td></tr><tr style="box-sizing:border-box"><td id="gmail-L672" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC672" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">         }</td></tr><tr style="box-sizing:border-box"><td id="gmail-L673" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC673" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">     msg = <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">more_result_sets</span>(state);</td></tr><tr style="box-sizing:border-box"><td id="gmail-L674" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC674" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">            <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">/* We don't want to continue if an error occured */</span></td></tr><tr style="box-sizing:border-box"><td id="gmail-L675" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC675" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">          <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> (msg.<span class="gmail-pl-smi" style="box-sizing:border-box">length</span> != <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">0</span>) { </td></tr><tr style="box-sizing:border-box"><td id="gmail-L676" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC676" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">            <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">break</span>;</td></tr><tr style="box-sizing:border-box"><td id="gmail-L677" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC677" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">         }</td></tr><tr style="box-sizing:border-box"><td id="gmail-L678" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC678" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre"> } <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">while</span> (<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">exists_more_result_sets</span>(state)); </td></tr><tr style="box-sizing:border-box"><td id="gmail-L679" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC679" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">     </td></tr><tr style="box-sizing:border-box"><td id="gmail-L680" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC680" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">      <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">ei_x_encode_empty_list</span>(&<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">dynamic_buffer</span>(state));</td></tr><tr style="box-sizing:border-box"><td id="gmail-L681" class="gmail-blob-num gmail-js-line-number" style="box-sizing:border-box;padding:0px 10px;width:50px;min-width:50px;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;line-height:20px;color:rgba(0,0,0,0.298039);text-align:right;white-space:nowrap;vertical-align:top"></td><td id="gmail-LC681" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line" style="box-sizing:border-box;padding:0px 10px;line-height:20px;vertical-align:top;overflow:visible;font-family:consolas,"liberation mono",menlo,courier,monospace;font-size:12px;word-wrap:normal;white-space:pre">    }</td></tr></tbody></table><p class="gmail-p1"><span class="gmail-s1"><br></span></p></div></div>