go-mysql
go-mysql copied to clipboard
add pattern replace
Hi~
Currently, characters are not substituted correctly in the lower case.
select * from test where a = 3*3
=> select * from test where a = ?*3
select * from test where a = ''''
=> select * from test where a = ??
First, I inserted a space character before and after the arithmetic operation code between the numbers to recognize the pattern correctly.
select * from test where a = 3*3
=> select * from test where a = 3 * 3
=> select * from test where a = ? * ?
Second, I have added code to replace from several question mark to single one
select * from test where a = ''''
=> select * from test where a = ??
=> select * from test where a = ?
Depending on the incoming parameters, the same query may be converted to two different fingerprints, so we want to fix it.
Thanks. Chan.
Ok, then it'd be better replace some pattern first and make fingerprint. ex)
select /* my comment */ * from `mydb+1`.`tab-001` where x = 1*1 and x2 = 'mydb+1';
## step 1
select %s * from %s.%s where x = 1*1 and x2 = ?;
## step 2
select %s * from %s.%s where x = 1 * 1 and x2 = ?;
## step 3
select %s * from %s.%s where x = ? * ? and x2 = ?;
## step 4
select /* my comment */ * from `mydb+1`.`tab-001` where x = ? * ? and x2 = ?;
What do you think about this?