add column escaper function

This commit is contained in:
Simon Vieille 2024-07-18 17:05:30 +02:00
commit 5eb3701f9f
Signed by untrusted user: deblan
GPG key ID: 579388D585F70417
2 changed files with 3 additions and 3 deletions

View file

@ -21,10 +21,10 @@ func EscapeColumn(dbType, col string) string {
func GetNamedParameter(dbType, col string, number int) string { func GetNamedParameter(dbType, col string, number int) string {
if dbType == "mysql" { if dbType == "mysql" {
return fmt.Sprintf("%s=?", EscapeColumn(col)) return fmt.Sprintf("%s=?", EscapeColumn(dbType, col))
} }
return fmt.Sprintf("%s=$%d", EscapeColumn(col), number) return fmt.Sprintf("%s=$%d", EscapeColumn(dbType, col), number)
} }
func IsPgNumberType(value string) bool { func IsPgNumberType(value string) bool {

View file

@ -19,7 +19,7 @@ func TestEscapeColumn(t *testing.T) {
t.Fatalf("TestEscapeColumn: mysql check failed") t.Fatalf("TestEscapeColumn: mysql check failed")
} }
if EscapeTable("postgres", "foo") != "\"foo\"" { if EscapeColumn("postgres", "foo") != "\"foo\"" {
t.Fatalf("TestEscapeColumn: postgres check failed") t.Fatalf("TestEscapeColumn: postgres check failed")
} }
} }