3
Copyright (C) 2007 MySQL AB
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
-- read_query() can rewrite packets
23
-- You can use read_query() to replace the packet sent by the client and rewrite
26
-- @param packet the mysql-packet sent by the client
29
-- * nothing to pass on the packet as is,
30
-- * proxy.PROXY_SEND_QUERY to send the queries from the proxy.queries queue
31
-- * proxy.PROXY_SEND_RESULT to send your own result-set
33
function read_query( packet )
34
if string.byte(packet) == proxy.COM_QUERY then
35
print("we got a normal query: " .. string.sub(packet, 2))
37
proxy.queries:append(1, packet )
38
-- generate a new COM_QUERY packet
40
-- and inject it with the id = 2
41
proxy.queries:append(2, string.char(proxy.COM_QUERY) .. "SELECT NOW()" )
43
return proxy.PROXY_SEND_QUERY
48
-- read_query_result() is called when we receive a query result
51
-- we can analyze the response, drop the response and pass it on (default)
53
-- as we injected a SELECT NOW() above, we don't want to tell the client about it
54
-- and drop the result with proxy.PROXY_IGNORE_RESULT
57
-- * nothing or proxy.PROXY_SEND_RESULT to pass the result-set to the client
58
-- * proxy.PROXY_IGNORE_RESULT to drop the result-set
60
function read_query_result(inj)
61
print("injected result-set: id = " .. inj.id)
63
-- inj.id = 2 was assigned above in the proxy.queries:append()
65
-- drop the resultset when we are done to hide it from the client
67
for row in inj.resultset.rows do
68
print("injected query returned: " .. row[0])
71
return proxy.PROXY_IGNORE_RESULT