MySQL Proxy Scripting
1419
• Unless your client is designed to cope with more result sets than queries, you should ensure that the
number of queries from the client match the number of results sets returned to the client. Using the
unique ID and removing result sets you inserted will help.
Normally, the
read_query()
and
read_query_result()
function are used in conjunction
with each other to inject additional queries and remove the additional result sets. However,
read_query_result()
is only called if you populate the query queue within
read_query()
.
15.7.4.8. Manipulating Results with
read_query_result()
The
read_query_result()
is called for each result set returned by the server only if you have
manually injected queries into the query queue. If you have not manipulated the query queue, this
function is not called. The function supports a single argument, the result packet, which provides a
number of properties:
•
id
: The ID of the result set, which corresponds to the ID that was set when the query packet was
submitted to the server when using
append(id)
on the query queue. You must have set the
resultset_is_needed
flag to
append
to intercept the result set before it is returned to the client.
See
proxy.queries [1411]
.
•
query
: The text of the original query.
•
query_time
: The number of microseconds required to receive the first row of a result set since the
query was sent to the server.
•
response_time
: The number of microseconds required to receive the last row of the result set
since the query was sent to the server.
•
resultset
: The content of the result set data.
By accessing the result information from the MySQL server, you can extract the results that match the
queries that you injected, return different result sets (for example, from a modified query), and even
create your own result sets.
The following Lua script, for example, will output the query, followed by the query time and response
time (that is, the time to execute the query and the time to return the data for the query) for each query
sent to the server:
function read_query( packet )
if packet:byte() == proxy.COM_QUERY then
print("we got a normal query: " .. packet:sub(2))
proxy.queries:append(1, packet )
return proxy.PROXY_SEND_QUERY
end
end
function read_query_result(inj)
print("query-time: " .. (inj.query_time / 1000) .. "ms")
print("response-time: " .. (inj.response_time / 1000) .. "ms")
end
You can access the rows of returned results from the result set by accessing the
rows
property of the
resultset
property of the result that is exposed through
read_query_result()
. For example, you
can iterate over the results showing the first column from each row using this Lua fragment:
for row in inj.resultset.rows do
print("injected query returned: " .. row[1])
end
Just like
read_query()
,
read_query_result()
can return different values for each result
according to the result returned. If you have injected additional queries into the query queue, for
example, remove the results returned from those additional queries and return only the results from the
query originally submitted by the client.
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...