lua-users home
lua-l archive

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


Hi all!
I created a client LUA that catches the query sent to a MySQL DB (using MySQL Proxy), writes it to a file .log and sends a message (for each queries captured) to
a SQL parser (written in java). The problem is this: When i enter a query such as "USE database;" the client first captures a "nil information" and then the
query; so it sends 2 messages instead of 1 to the Parser.
How can I fix this?
Thank you very much
 

socket = require("socket")

local c = socket.tcp()
local log_file = "C:/Users/Francesco/Desktop/Tesi/mysql-proxy/log_query.log"
local fd = io.open(log_file, "a+")
host="localhost"
porta=7777
function read_query( packet )
local c = socket.connect(host , porta)
local eccezione = socket.newtry(function() c:close() end)
if string.byte(packet) == proxy.COM_QUERY then
       
  local query = string.sub(packet, 2)
  if query=="SELECT DATABASE()" then query="USE DATABASE"
  end
  fd:write(string.format("%s;", query))
  
  fd:write(string.format("\n"))
  elseif string.byte(packet) == proxy.COM_QUIT then
   fd:write( "QUIT;")
   fd:write(string.format("\n"))

end
eccezione(c:send("Nuova query catturata\r\n"))
eccezione(c:send(query))
local answer = eccezione(c:receive('*l'))
print(answer)
fd:flush()
--end function
end
c:close()



Personalizza il tuo spazio online: ritagliati il tuo Spaces