--- /dev/null
+-- unfuck the cpath set by mysql-proxy and load sqlite3 driver
+package.cpath=package.cpath .. ";/usr/lib/i386-linux-gnu/lua/5.1/?.so"
+require "luasql.sqlite3"
+
+-- intercept mysql queries
+function read_query( packet )
+ if packet:byte() == proxy.COM_QUERY then
+ print("DEBUG: we got a normal query: " .. packet:sub(2))
+ local query = string.sub(packet, 2)
+
+ if string.match(string.upper(query), '^%s*INSERT') then
+ print("DEBUG: found a query to process")
+ -- create environment object
+ local env = assert (luasql.sqlite3())
+ -- connect to data source
+ local con = assert (env:connect("mydb.sqlite3"))
+
+ -- act on the database
+ -- local cur = assert (con:execute(query))
+ local cur = con:execute(query)
+
+ -- closing time
+ cur:close()
+ con:close()
+ env:close()
+ end
+ end
+end
+
--- /dev/null
+mysql proxy startup command:
+
+mysql-proxy --admin-username=a --admin-password=b --admin-lua-script=/usr/share/mysql-proxy/admin.lua --proxy-backend-addresses=127.0.0.1:3306 --proxy-lua-script=/home/sven/myscript.lua
+
+
+Introduction:
+http://www.oreillynet.com/pub/a/databases/2007/07/12/getting-started-with-mysql-proxy.html