You should not be running escapeSQLString on the entire string. You should only be using escapeSQLString on parameters in the query that would be from user input. For instance:
local query = format("INSERT INTO `table` (`col1`, `col2`, `col3`) VALUES (1, 'hardcoded string', '%s')", escapeSQLString(arguments));
QuerySQL(database, query);