diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-05-12 13:34:58 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-05-12 13:34:58 +0200 |
| commit | b3129b483ed3e1a0294dac9da44d5f56ae4746e2 (patch) | |
| tree | d46c8e0c0c9b28eef921fbf8b9cf18181486b31c /dialect.go | |
| parent | 80c3fadf24fe9d784d876eec247fd6799af49c8a (diff) | |
| download | go-oblast-b3129b483ed3e1a0294dac9da44d5f56ae4746e2.tar.gz | |
add escaping in Dialect.QuoteIdentifier implementations
Diffstat (limited to 'dialect.go')
| -rw-r--r-- | dialect.go | 28 |
1 files changed, 22 insertions, 6 deletions
@@ -44,8 +44,13 @@ func MariaDBDialect() Dialect { type mariadbDialect struct{} -func (mariadbDialect) Placeholder(_ int) string { return "?" } -func (mariadbDialect) QuoteIdentifier(name string) string { return "`" + name + "`" } +func (mariadbDialect) Placeholder(_ int) string { + return "?" +} + +func (mariadbDialect) QuoteIdentifier(name string) string { + return "`" + strings.ReplaceAll(name, "`", "``") + "`" +} func (d mariadbDialect) UpsertClause(pkColumns, otherColumns []string) string { clauses := make([]string, max(1, len(otherColumns))) @@ -68,8 +73,13 @@ func PostgresDialect() Dialect { type postgresDialect struct{} -func (postgresDialect) Placeholder(i int) string { return "$" + strconv.Itoa(i+1) } -func (postgresDialect) QuoteIdentifier(name string) string { return `"` + name + `"` } +func (postgresDialect) Placeholder(i int) string { + return "$" + strconv.Itoa(i+1) +} + +func (postgresDialect) QuoteIdentifier(name string) string { + return `"` + strings.ReplaceAll(name, `"`, `""`) + `"` +} func (d postgresDialect) UpsertClause(pkColumns, otherColumns []string) string { quotedPkColumns := make([]string, len(pkColumns)) @@ -98,8 +108,14 @@ func SqliteDialect() Dialect { type sqliteDialect struct{} -func (sqliteDialect) Placeholder(_ int) string { return "?" } -func (sqliteDialect) QuoteIdentifier(name string) string { return `"` + name + `"` } +func (sqliteDialect) Placeholder(_ int) string { + return "?" +} + +func (sqliteDialect) QuoteIdentifier(name string) string { + return `"` + strings.ReplaceAll(name, `"`, `""`) + `"` +} + func (sqliteDialect) UpsertClause(pkColumns, otherColumns []string) string { return postgresDialect{}.UpsertClause(pkColumns, otherColumns) } |
