Skip to content

Commit d78d4c7

Browse files
authored
Merge pull request #2995 from dolthub/tim/fix-enum-ecaping
Fixed enum escaping issue
2 parents ce4535e + e6bd07c commit d78d4c7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

sql/types/enum.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,11 @@ func (t EnumType) WithNewCollation(collation sql.CollationID) (sql.Type, error)
359359

360360
// StringWithTableCollation implements sql.TypeWithCollation interface.
361361
func (t EnumType) StringWithTableCollation(tableCollation sql.CollationID) string {
362-
s := fmt.Sprintf("enum('%v')", strings.Join(t.idxToVal, `','`))
362+
escapedValues := make([]string, len(t.idxToVal))
363+
for i, value := range t.idxToVal {
364+
escapedValues[i] = strings.ReplaceAll(value, "'", "''")
365+
}
366+
s := fmt.Sprintf("enum('%s')", strings.Join(escapedValues, `','`))
363367
if t.CharacterSet() != tableCollation.CharacterSet() {
364368
s += " CHARACTER SET " + t.CharacterSet().String()
365369
}

sql/types/set.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,12 @@ func (t SetType) WithNewCollation(collation sql.CollationID) (sql.Type, error) {
306306

307307
// StringWithTableCollation implements sql.TypeWithCollation interface.
308308
func (t SetType) StringWithTableCollation(tableCollation sql.CollationID) string {
309-
s := fmt.Sprintf("set('%v')", strings.Join(t.Values(), `','`))
309+
values := t.Values()
310+
escapedValues := make([]string, len(values))
311+
for i, value := range values {
312+
escapedValues[i] = strings.ReplaceAll(value, "'", "''")
313+
}
314+
s := fmt.Sprintf("set('%s')", strings.Join(escapedValues, `','`))
310315
if t.CharacterSet() != tableCollation.CharacterSet() {
311316
s += " CHARACTER SET " + t.CharacterSet().String()
312317
}

0 commit comments

Comments
 (0)