How to compare query with string in lua scripting?

170 views Asked by At

I have created a Mysql-proxy using lua scripting. For some particular query, i want to override the resultset with some other data. But while comparing query with string, it is showing false while print in console have same value. Please check the below code:

function read_query_result (inj)
   print_access('inside read_query_result \t' .. inj.query)
   print(string.lower(inj.query))    //printing "show databases" in console
   local query = string.lower(inj.query)
   print(query == "show databases")  //printing false

  if query == "show databases" then 
   proxy.response.type = proxy.MYSQLD_PACKET_OK
   proxy.response.resultset = {
     fields = {
                { type = proxy.MYSQL_TYPE_LONG, name = "votee", },
                { type = proxy.MYSQL_TYPE_LONG, name = "count", },
                { type = proxy.MYSQL_TYPE_STRING, name = "testvar", },
              },
     rows = {
                { 1, 3, "BLR" }
            }
    }
    print("--------- end looping")
    return proxy.PROXY_SEND_RESULT
  end

end

Even, i am running "show databases" query in the mysql, it is not going inside the if condition.

What i want here is based on the mysql query i should be able to control the condition and customize the resultset accordingly. It would be very helpful if i will get your help. Thanks in advance.

0

There are 0 answers