Fixed value replacement and added more tests for canonicalization of queries

The value replacement was not taking session or system variables into notice.
This commit is contained in:
Markus Makela
2016-01-07 12:04:55 +02:00
parent 995ed8c9d2
commit 9c9e30fa08
4 changed files with 155 additions and 5 deletions

View File

@ -57,8 +57,8 @@ int main(int argc, char** argv)
return 1; return 1;
} }
while (!feof(infile)) while (!feof(infile) && fgets(readbuff, 4092, infile))
{ {
fgets(readbuff,4092,infile); fgets(readbuff,4092,infile);
char* nl = strchr(readbuff, '\n'); char* nl = strchr(readbuff, '\n');
if(nl) if(nl)

View File

@ -15,4 +15,78 @@ delete from tst where lname like '?' and fname like '?';
select ? from tst where fname='?' or lname like '?'; select ? from tst where fname='?' or lname like '?';
select ?,?,?,? from tst where name='?' or name='?' or name='?' or name='?'; select ?,?,?,? from tst where name='?' or name='?' or name='?' or name='?';
select count(?),count(?),count(?),count(?),count (?),count(?) from tst; select count(?),count(?),count(?),count(?),count (?),count(?) from tst;
select count(?),count(?),count(?),count(?),count (?),count(?) from tst; begin;
BEGIN
BEGIN;
commit;
COMMIT;
COMMIT;
CREATE DATABASE FOO;
CREATE EVENT myevent
CREATE FUNCTION hello (s CHAR(?))
CREATE INDEX foo_t1 on T1 (id);
CREATE PROCEDURE simpleproc (OUT param1 INT)
CREATE TABLE myCity (a int, b char(?));
create table t1 (id integer);
create table t1(id integer);
CREATE TABLE T1 (id integer);
CREATE TABLE T1 (id integer);
CREATE TABLE T2 (id integer);
CREATE TEMPORARY TABLE T1 (id integer);
DELETE FROM myCity;
DELETE FROM myCity;
DELIMITER ;//
DELIMITER //;
DO
DROP DATABASE FOO;
DROP DATABASE If EXISTS FOO;
DROP EVENT IF EXISTS myevent;
DROP EVENT myevent;
DROP FUNCTION hello;
DROP FUNCTION IF EXISTS hello;
DROP PROCEDURE IF EXISTS simpleproc;
DROP PROCEDURE simpleproc;
DROP TABLE IF EXISTS myCity;
drop table if exists t1;
DROP TABLE IF EXISTS T1;
DROP TABLE IF EXISTS T2;
DROP TABLE myCity;
drop table t1;
DROP TABLE T1;
DROP TABLE T2;
END //
INSERT INTO myCity VALUES (?, '?');
INSERT INTO myCity VALUES (?, '?');
insert into t1 values(?);
insert into t1 values(?);
INSERT INTO T2 VALUES (@@?);
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL ? HOUR
RETURN CONCAT('?',s,'?');
RETURNS CHAR(?) DETERMINISTIC
SELECT @?;
SELECT @?;
SELECT COUNT(*) FROM myCity;
select count(*) from t1;
select count(*) from t1;
select count(*) from user where user='?';
SELECT COUNT(*) INTO param1 FROM t;
SELECT IF(@? <> @?,'?','?') AS result;
SELECT IF(id <> @?,'?','?') AS result FROM T2;
SELECT IF(@@? <> @?,'?','?') AS result;
SELECT (@@?) INTO @?;
set autocommit=?;
SET autocommit=?;
SET autocommit = ?;
set autocommit=?;
SET autocommit=?;
SET AUTOCOMMIT=?;
set autocommit=OFF;
SET autocommit = oFf;
SET autocommit = Off;
SET AUTOCOMMIT=oN;
START TRANSACTION;
UPDATE t1 SET id = id + ?;
use mysql;
use test;
USE test;
USE test;

View File

@ -15,3 +15,78 @@ delete from tst where lname like '%man%' and fname like '%ard%';
select 100 from tst where fname='10' or lname like '%100%'; select 100 from tst where fname='10' or lname like '%100%';
select 1,20,300,4000 from tst where name='1000' or name='200' or name='30' or name='4'; select 1,20,300,4000 from tst where name='1000' or name='200' or name='30' or name='4';
select count(1),count(10),count(100),count(2),count (20),count(200) from tst; select count(1),count(10),count(100),count(2),count (20),count(200) from tst;
begin;
BEGIN
BEGIN;
commit;
COMMIT;
COMMIT;
CREATE DATABASE FOO;
CREATE EVENT myevent
CREATE FUNCTION hello (s CHAR(20))
CREATE INDEX foo_t1 on T1 (id);
CREATE PROCEDURE simpleproc (OUT param1 INT)
CREATE TABLE myCity (a int, b char(20));
create table t1 (id integer);
create table t1(id integer);
CREATE TABLE T1 (id integer);
CREATE TABLE T1 (id integer);
CREATE TABLE T2 (id integer);
CREATE TEMPORARY TABLE T1 (id integer);
DELETE FROM myCity;
DELETE FROM myCity;
DELIMITER ;//
DELIMITER //;
DO
DROP DATABASE FOO;
DROP DATABASE If EXISTS FOO;
DROP EVENT IF EXISTS myevent;
DROP EVENT myevent;
DROP FUNCTION hello;
DROP FUNCTION IF EXISTS hello;
DROP PROCEDURE IF EXISTS simpleproc;
DROP PROCEDURE simpleproc;
DROP TABLE IF EXISTS myCity;
drop table if exists t1;
DROP TABLE IF EXISTS T1;
DROP TABLE IF EXISTS T2;
DROP TABLE myCity;
drop table t1;
DROP TABLE T1;
DROP TABLE T2;
END //
INSERT INTO myCity VALUES (1, 'Milan');
INSERT INTO myCity VALUES (2, 'London');
insert into t1 values(1);
insert into t1 values(1);
INSERT INTO T2 VALUES (@@server_id);
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
RETURN CONCAT('Hello, ',s,'!');
RETURNS CHAR(50) DETERMINISTIC
SELECT @a;
SELECT @a;
SELECT COUNT(*) FROM myCity;
select count(*) from t1;
select count(*) from t1;
select count(*) from user where user='maxuser';
SELECT COUNT(*) INTO param1 FROM t;
SELECT IF(@a <> @TMASTER_ID,'OK (slave)','FAIL (master)') AS result;
SELECT IF(id <> @TMASTER_ID,'OK (slave)','FAIL (master)') AS result FROM T2;
SELECT IF(@@server_id <> @TMASTER_ID,'OK (slave)','FAIL (master)') AS result;
SELECT (@@server_id) INTO @a;
set autocommit=0;
SET autocommit=0;
SET autocommit = 0;
set autocommit=1;
SET autocommit=1;
SET AUTOCOMMIT=1;
set autocommit=OFF;
SET autocommit = oFf;
SET autocommit = Off;
SET AUTOCOMMIT=oN;
START TRANSACTION;
UPDATE t1 SET id = id + 1;
use mysql;
use test;
USE test;
USE test;

View File

@ -2033,7 +2033,8 @@ void skygw_file_close(
static pcre2_code* replace_values_re = NULL; static pcre2_code* replace_values_re = NULL;
static const PCRE2_SPTR replace_values_pattern = (PCRE2_SPTR) "(?i)([-=,+*/([:space:]]|\\b)([0-9.]+|NULL)([-=,+*/)[:space:];]|$)"; static const PCRE2_SPTR replace_values_pattern = (PCRE2_SPTR) "(?i)([-=,+*/([:space:]]|\\b|[@])"
"(?:[0-9.]+|(?<=[@])[a-z_]+|NULL)([-=,+*/)[:space:];]|$)";
/** /**
* Replace every literal number and NULL value with a question mark. * Replace every literal number and NULL value with a question mark.
@ -2042,7 +2043,7 @@ static const PCRE2_SPTR replace_values_pattern = (PCRE2_SPTR) "(?i)([-=,+*/([:sp
*/ */
char* replace_values(const char* str) char* replace_values(const char* str)
{ {
static const PCRE2_SPTR replace = (PCRE2_SPTR) "$1?$3"; static const PCRE2_SPTR replace = (PCRE2_SPTR) "$1?$2";
pcre2_match_data* mdata; pcre2_match_data* mdata;
size_t orig_len = strlen(str); size_t orig_len = strlen(str);
size_t len = orig_len; size_t len = orig_len;