What happens if one of the queries in the pipeline generates an error?
If you don't handle this occurrence, the Proxy will continue sending to the server all the queries in the pipeline, regardless of the result. It's easy to understand that, if the second query depends on the execution of the first one, checking the result of each query is essential.
We know already how to return an error. We only need to apply that knowledge in the right place.
read_query_result()from the previous recipe (executing multiple queries) should be modified as follows:
The error status is inside the resultset, which is contained in the injection packet received by the function. If that status is negative, some error occurred.
function read_query_result (inj )
local res = assert(inj.resultset)
if res.query_status and (res.query_status < 0 ) then
return error_result('ERROR IN LOOP ' .. tostring(inj.id),
-- do something with the result
if inj.id ~= max_loop then
This post is part of a set of recipes that will eventually become a long article.
Want to hear more? Attend MySQL Proxy - The complete tutorial at the MySQL Users Conference 2008.