0

I am using lua script https://github.com/clofresh/mysql-proxy-cache to cache the select query. But there is a problem with the way it is detecting select statement. It is using following code

return query:sub(1,6):lower() == 'select'

This will not work if select query is nested in (). Example:

(SELECT * from tbl_name);

Is there a way to remove extra () in mysql proxy ?

or Is there a better way to detect select query?

Vivek Goel
  • 22,942
  • 29
  • 114
  • 186

2 Answers2

0

I would try to write a normalizing script using the String Library that detect common patterns and replaces them with equivalent normalized sql.

One example is your parenteses but also queries where the where parts have been moved around could benefit from this.

Andreas Wederbrand
  • 38,065
  • 11
  • 68
  • 78
0

The queries are actually inside of the the parentheses, not inside of a string? That shouldn't parse correctly, even with a plug in. If it is in a string then simply use :sub(2, 7), however, if it is not, then put it inside of a string. Create a function that basically reproduces the function, except puts it in a string, e.g.:

function mysqlQuery(mysqlString)
    loadstring(mysqlString)(); 
    return mysqlString;
end
mysqlQuery("SELECT * from tbl");
cygorx
  • 228
  • 1
  • 2
  • 19