0

So I'm building a C program that connects to a mySQL database. Everything worked perfectly. Then, to save on number of queries, I decided that I would like to execute 10 statements at a time. I set the "CLIENT_MULTI_STATEMENTS" flag in the connection, and separated my statements by semicolons.

When I execute the first batch of 10 statements, it succeeds and mysql_real_query() returns a 0.

When I try the second batch though, it returns a "1" and doesn't work. Nowhere can I find what this "1" error code means, so I was hoping someone may have run into this problem before.

Please note that these are all UPDATE statements, and so I have no need for result sets, it's just several straight-up calls to mysql_real_query().

2 Answers 2

3

It's not clear from the documentation whether the errors this function can cause are returned or not, but it should be possible to obtain the actual error using mysql_error().

My guess is that you still have to loop through the result sets whether you're interested in them or not.`

Sign up to request clarification or add additional context in comments.

Comments

3

Are these prepared statements? If that's the case then you can't use CLIENT_MULTI_STATEMENTS.

Also, note (from http://dev.mysql.com/doc/refman/5.5/en/c-api-multiple-queries.html) that:

After handling the result from the first statement, it is necessary to check whether more results exist and process them in turn if so. To support multiple-result processing, the C API includes the mysql_more_results() and mysql_next_result() functions. These functions are used at the end of a loop that iterates as long as more results are available. Failure to process the result this way may result in a dropped connection to the server.

You have to walk over all the results, regardless of whether or not you care about the values.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.