--[[ * Example how can be change destination table of * a LOAD DATA LOCAL INLINE statement. ]] ------------------------------------------------------------------------------------------ -- Read client query and inject function for LOAD DATA INFILE LOCAL query ------------------------------------------------------------------------------------------ function read_query(packet) if packet:byte() ~= proxy.COM_QUERY then return end local q = packet:sub(2) if DEBUG then log( "Received query: " .. q, MSG_IMPORTANT ) end if string.find( string.lower( q ), 'load data local' ) then local table_name = split( q, " " ) local tbl_name = string.gsub( table_name[8], "`", "" ) local file_name = string.gsub( table_name[5], "'", "" ) local tmp_table = "NEW_TABLE" proxy.queries:append( 1, string.char(proxy.COM_QUERY) .. "LOAD DATA LOCAL INFILE '" .. file_name .. "' INTO TABLE `" .. tmp_table .. "`", { resultset_is_needed = true } ) proxy.queries:append( 2, string.char(proxy.COM_QUERY) .. "SHOW WARNINGS", { resultset_is_needed = true } ) else proxy.queries:append( 1, packet, { resultset_is_needed = true } ) end return proxy.PROXY_SEND_QUERY end ------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------ -- Catch result and send result to client ------------------------------------------------------------------------------------------ function read_query_result(inj) local res = assert(inj.resultset) if inj.id == 2 then return proxy.PROXY_IGNORE_RESULT end proxy.response = { type = proxy.MYSQLD_PACKET_OK, affected_rows = inj.resultset.affected_rows } end ------------------------------------------------------------------------------------------