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