Skip to content

Commit a74727b

Browse files
Fix Fingerprint() to make it work correctly with MAX_EXECUTION_TIME statement (#63)
* Add tests for Fingerprint() with MAX_EXECUTION_TIME statement * Fix Fingerprint() to make it work correctly with MAX_EXECUTION_TIME statement
1 parent 73d29c6 commit a74727b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

query/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ func Fingerprint(q string) string {
541541
// so advance cpFromOffset to whatever is after the space
542542
// and if it's more space then space skipping block will
543543
// handle it.
544-
cpFromOffset = qi + 1
545544
}
545+
cpFromOffset = qi + 1
546546
} else if s == inDash {
547547
if Debug {
548548
fmt.Println("One-line comment begin")

query/query_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,22 @@ func TestFingerprintWithNumberInDbName(t *testing.T) {
650650
query.Fingerprint(q),
651651
)
652652
}
653+
654+
func TestFingerprintMaxExecTimeWithBackticks(t *testing.T) {
655+
q := "/* test-test-5775b87c5d-fczwg|@test-test|test-test|internal|/internal/test|test-test */\n\n SELECT /*+ MAX_EXECUTION_TIME(7995) */ `id`, `domain`, `city_id`, `name`, `polygon`, `state`, `translations` AS `translations`\n FROM `area`\n WHERE `state` IN ('active', 'disabled', 'removed') AND `domain` = 'test'"
656+
657+
assert.Equal(
658+
t,
659+
"select `id`, `domain`, `city_id`, `name`, `polygon`, `state`, `translations` as `translations` from `area` where `state` in(?+) and `domain` = ?",
660+
query.Fingerprint(q),
661+
)
662+
}
663+
664+
func TestFingerprintMaxExecTimeNoBackticks(t *testing.T) {
665+
q := "/* test-test-5775b87c5d-fczwg|@test-test|test-test|internal|/internal/test|test-test */\n\n SELECT /*+ MAX_EXECUTION_TIME(7995) */ id, domain, city_id, name, polygon, state, translations AS translations\n FROM area\n WHERE state IN ('active', 'disabled', 'removed') AND domain = 'test'"
666+
667+
assert.Equal(t,
668+
"select id, domain, city_id, name, polygon, state, translations as translations from area where state in(?+) and domain = ?",
669+
query.Fingerprint(q),
670+
)
671+
}

0 commit comments

Comments
 (0)