Using OTL, error: MySQL Commands out of sync; You can ' t run the This command now

Source: Internet
Author: User
Tags mysql commands sprintf

1, the code is as follows:

voidTestcache (otl_connect&otlconn) {    Try    {        Charsql[1024x768] = {0}; sprintf (SQL,"Call test1 (1)"); Otl_stream Stream ( -, SQL, otlconn,otl_implicit_select); intID;  while(!stream.eof ()) {Stream>>ID; Charsql2[1024x768] = {0}; sprintf (SQL2,"Call test2 (:id<int>)"); Otl_stream stream2 ( -, SQL2, Otlconn,otl_implicit_select); Stream2<<ID;  while(!stream2.eof ()) {                intFF =0; }        }    }    Catch(otl_exception&ex) {printf ("ExecuteSQL Error, errormsg[%s], sql[%s]", Ex.msg, Ex.stm_text); }}

2, the implementation of Otl_stream stream2 (SQL2, Otlconn,otl_implicit_select), the time of the error, as follows:

Commands out of sync; You can ' t run the This command now
3, error reason: MySQL last query did not release the result set, and the next query.
4, OTL: During the first stream read, the second stream uses a binding variable, which causes the problem above, and does not know how the OTL inside is encapsulated.
5, the solution:
A, the second stream does not use a binding variable, as follows:

voidTestcache (otl_connect&otlconn) {    Try    {        Charsql[1024x768] = {0}; sprintf (SQL,"Call test1 (1)"); Otl_stream Stream ( -, SQL, otlconn,otl_implicit_select); intID;  while(!stream.eof ()) {Stream>>ID; Charsql2[1024x768] = {0}; sprintf (SQL2,"Call test2 (%d)", id); Otl_stream stream2 ( -, SQL2, Otlconn,otl_implicit_select);  while(!stream2.eof ()) {                intFF =0; }        }    }    Catch(otl_exception&ex) {printf ("ExecuteSQL Error, errormsg[%s], sql[%s]", Ex.msg, Ex.stm_text); }}   

b, first read the first stream, and then a second stream, as follows:

voidTestcache (otl_connect&otlconn) {    Try    {        Charsql[1024x768] = {0}; sprintf (SQL,"Call test1 (1)"); Otl_stream Stream ( -, SQL, otlconn,otl_implicit_select); Vector<int>Intvec; intID;  while(!stream.eof ()) {Stream>>ID;                    Intvec.push_back (ID); }         for(vector<int>::iterator iter =Intvec.begin (); ITER! = Intvec.end (); ++ITER) {            Charsql2[1024x768] = {0}; sprintf (SQL2,"Call test2 (:id<int>)"); Otl_stream stream2 ( -, SQL2, Otlconn,otl_implicit_select); Stream2<<ID;  while(!stream2.eof ()) {                intFF =0; }        }    }    Catch(otl_exception&ex) {printf ("ExecuteSQL Error, errormsg[%s], sql[%s]", Ex.msg, Ex.stm_text); }}

Using OTL, error: MySQL Commands out of sync; You can ' t run the This command now

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.