diff --git a/query/query.go b/query/query.go index 5921131..6ec8087 100644 --- a/query/query.go +++ b/query/query.go @@ -134,7 +134,8 @@ var ReplaceNumbersInWords = false func Fingerprint(q string) string { q += " " // need range to run off end of original query prevWord := "" - f := make([]byte, len(q)) + // allocate enough memory to replace (x) with (?+). + f := make([]byte, len(q)+len(q)/3) fi := 0 pr := rune(0) // previous rune s := unknown // current state diff --git a/query/query_test.go b/query/query_test.go index ad3d75c..c99d6ec 100644 --- a/query/query_test.go +++ b/query/query_test.go @@ -248,6 +248,13 @@ func (s *TestSuite) TestFingerprintBasic(t *C) { "select sql_small_result sql_cache distinct centro_atividade from est_dia where unidade_id=? and item_id=? and item_id_red=?", ) + q = "insert into foo (a) values(0)" + t.Check( + query.Fingerprint(q), + Equals, + "insert into foo (a) values(?+)", + ) + q = "INSERT INTO t (ts) VALUES (NOW())" t.Check( query.Fingerprint(q),