fix dashboard SQL placeholders

This commit is contained in:
zhx 2026-07-08 20:03:52 +08:00
parent 24893460bc
commit 289ee7316b
2 changed files with 27 additions and 2 deletions

View File

@ -666,11 +666,11 @@ GROUP BY d.sys_origin, d.country_code`, statTimezone, statTimezone, sysOrigin, s
} }
func inPlaceholders(count int) string { func inPlaceholders(count int) string {
return "(" + placeholders(count, 1) + ")" return "(" + strings.TrimRight(strings.Repeat("?,", count), ",") + ")"
} }
func inStringPlaceholders(count int) string { func inStringPlaceholders(count int) string {
return "(" + placeholders(count, 1) + ")" return inPlaceholders(count)
} }
func stringArgs(values []string) []interface{} { func stringArgs(values []string) []interface{} {

View File

@ -0,0 +1,25 @@
package storage
import "testing"
func TestInPlaceholdersUsesScalarList(t *testing.T) {
tests := []struct {
name string
count int
want string
}{
{name: "single", count: 1, want: "(?)"},
{name: "multiple", count: 3, want: "(?,?,?)"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := inPlaceholders(tt.count); got != tt.want {
t.Fatalf("inPlaceholders(%d) = %q, want %q", tt.count, got, tt.want)
}
if got := inStringPlaceholders(tt.count); got != tt.want {
t.Fatalf("inStringPlaceholders(%d) = %q, want %q", tt.count, got, tt.want)
}
})
}
}