[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: pattern matching and replacing
- From: "daniel rahmeh" <daniel.rahmeh@...>
- Date: Tue, 17 Jun 2008 14:43:46 +0200
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