fix: quote tdengine history inserts

This commit is contained in:
lingniu
2026-07-01 22:06:12 +08:00
parent 80474eeccb
commit 60ca42e5d5
2 changed files with 55 additions and 3 deletions

View File

@@ -45,6 +45,13 @@ func TestWriterAppendsRawLocationAndMileage(t *testing.T) {
if got := countSQL(exec.calls, "INSERT INTO mil_"); got != 1 {
t.Fatalf("mileage insert count = %d", got)
}
rawInsert := findSQL(exec.calls, "INSERT INTO raw_")
if !strings.Contains(rawInsert, "'go_") || !strings.Contains(rawInsert, "'2e") && !strings.Contains(rawInsert, "'") {
t.Fatalf("raw insert should quote string literals: %s", rawInsert)
}
if strings.Contains(rawInsert, "VALUES (?,") {
t.Fatalf("raw insert should not use placeholders for tdengine websocket plain insert: %s", rawInsert)
}
}
func TestWriterSkipsSparseDerivedRows(t *testing.T) {
@@ -103,6 +110,15 @@ func countSQL(calls []execCall, pattern string) int {
return count
}
func findSQL(calls []execCall, pattern string) string {
for _, call := range calls {
if strings.Contains(call.query, pattern) {
return call.query
}
}
return ""
}
type execCall struct {
query string
args []any