MySQL Forums
Forum List  »  Router & Proxy

Change Database base on query
Posted by: Matt Piskorz
Date: July 07, 2009 04:48PM

Good day,

I'm trying to get familiar with the proxy and I'm trying to have the query change the database depending upon if its a read or a write.

Basically, if it has a select in it, I want it to get to proxy_read and all the other statements should go to proxy_write.

I've been looking through the tutorial scripts which I think have pointed me in the right direction, but I am having problems getting the result set back.

This is my lua function that I have put together from looking at the different tutorials:

function read_query (packet)
print(packet:sub(2))
print(packet:byte()..":"..proxy.COM_QUERY)
if packet:byte() == proxy.COM_QUERY then
if packet:sub(2,7) == "select" then
print(" query: " .. packet:sub(2))
proxy.queries:append(1,packet)
proxy.queries:prepend(1, string.char(proxy.COM_INIT_DB) .. "proxy_read", { resultset_is_needed = true })

return proxy.PROXY_SEND_QUERY
end
end

end

if I pass select * from test, the output is this: Query OK, 0 rows affected (0.00 sec)


if I do SELECT * from test, it then returns the row.

I realize that lua is case sensative, but I would have expected to get the result set back with "select" also.

"select * from test" returns the correct result set when I do not go through the proxy.

I've been mainly looking at tutorial-inject.lua.

Thanks taking a look at my post.

Matt

Options: ReplyQuote


Subject
Views
Written By
Posted
Change Database base on query
4688
July 07, 2009 04:48PM
2829
July 10, 2009 03:13PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.