Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/percona/go-mysql

go 1.24.2
go 1.23.4

require (
github.com/pkg/errors v0.9.1
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
Expand Down
23 changes: 16 additions & 7 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,13 @@ func Fingerprint(q string) string {
default:
if s != inWord && s != inOp {
// If in a word or operator then keep copying the query, else
// previous chars were being ignored for some reasons but now
// previous chars were being ignored for some reason, but now
// we should start copying again, so set cpFromOffset. Example:
// col=NOW(). 'col' will be set to copy, but then '=' will put
// us in inOp state which, if a value follows, will trigger a
// copy of "col=", but "NOW()" is not a value so "N" is caught
// here and since s=inOp still we do not copy yet (this block is
// is not entered).
// not entered).
if Debug {
fmt.Println("Random character")
}
Expand Down Expand Up @@ -766,12 +766,21 @@ func Fingerprint(q string) string {
copy(f[fi:fi+l], prevWord)
fi += l
cpFromOffset = cpToOffset
if wordIn(prevWord, "in", "value", "values") && sqlState != onDupeKeyUpdate {
// IN () -> in(?+)
// VALUES () -> values(?+)
valueKeywords := []string{"in", "value", "values"}
if wordIn(prevWord, valueKeywords...) && sqlState != onDupeKeyUpdate {
addSpace = false
s = inValues
sqlState = inValues
// since we only consider the keywords if it exists at a top-level (except onDupeKeyUpdate),
// we only do the conversion below if the "keywords" actually open a value list (i.e., before opening a parenthesis).
if r == '(' || (isSpace(r) && (q[qi+1] == '(') || (q[qi+1] == ' ')) {
// IN () -> in(?+)
// VALUES () -> values(?+)
s = inValues
sqlState = inValues
} else {
f[fi] = ' '
fi++
cpFromOffset++
}
} else if addSpace {
if Debug {
fmt.Println("Add space")
Expand Down
35 changes: 35 additions & 0 deletions query/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,41 @@ func TestFingerprintBasic(t *testing.T) {
query: "select * from foo limit 5 offset 10",
expected: "select * from foo limit ? offset ?",
},
{
name: "insert with quoted keyword as column",
query: "INSERT INTO test (ID, `Value`) VALUES (1 ,1)",
expected: "insert into test (id, `value`) values(?+)",
},
{
name: "insert with non-quoted keyword as column",
query: "INSERT INTO test (ID, Value) VALUES (1 ,1)",
expected: "insert into test (id, value) values(?+)",
},
{
name: "insert with non-quoted keyword and space as column",
query: "INSERT INTO test (ID, Value ) VALUES (1 ,1)",
expected: "insert into test (id, value ) values(?+)",
},
{
name: "insert with keyword as first column name",
query: "INSERT INTO test ( In , ID) VALUES (1,1)",
expected: "insert into test ( in , id) values(?+)",
},
{
name: "insert with value keyword as first column name",
query: "INSERT INTO test ( In , ID) VALUES (1,1)",
expected: "insert into test ( in , id) values(?+)",
},
{
name: "insert duplicate with keyword as column name",
query: "INSERT INTO test (id, value) VALUES (1, 10) ON DUPLICATE KEY UPDATE value = VALUES(value) + 5",
expected: "insert into test (id, value) values(?+) on duplicate key update value = values(value) + ?",
},
{
name: "insert duplicate with keyword and space as column name",
query: "INSERT INTO test (id, value ) VALUES (1, 10) ON DUPLICATE KEY UPDATE value = VALUES(value ) + 5",
expected: "insert into test (id, value ) values(?+) on duplicate key update value = values(value ) + ?",
},
{
name: "fingerprint load data infile",
query: "LOAD DATA INFILE '/tmp/foo.txt' INTO db.tbl",
Expand Down