lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

i'm trying to do some pattern matching and replacing using lua. In
fact i want MySQL Proxy to modify my SQL query before resending it to
my DBMS

my original query is: Insert into sometable (username, password,
phone) values ('test', 'tespasswd', '123456789')

i want my query to be modified to: Insert into sometable (username,
password, phone) values ('test', SHA1('tespasswd'), '123456789')

i'm unable to find the correct pattern, i tried this:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if string.match(query, 'insert into users (username, pass, telephone)
values ("%w+", "%w+", "%w+")') then

query = string.gsub(query,'insert into users (username, password,
telephone) values ('%w+', '%w+', '%w+')', 'insert into users
(username, password, telephone) values ('%w+', SHA1('%w+'), '%w+')')

end

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

obviously it's not the correct way to do it

any help will be appreciated

thank you

note: i know it can be done on the DBMS but i'm testing the MySQL Proxy features