Skip to content

Commit 6aaf629

Browse files
committed
Adding back the QuoteString util
1 parent 8f50fac commit 6aaf629

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

server/types/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package types
1616

1717
import (
1818
"fmt"
19+
"strings"
1920
"time"
2021
"unicode/utf8"
2122

@@ -24,6 +25,17 @@ import (
2425
"github.com/dolthub/vitess/go/vt/proto/query"
2526
)
2627

28+
// QuoteString will quote the string according to the type given. This means that some types will quote, and others will
29+
// not, or they may quote in a special way that is unique to that type.
30+
func QuoteString(baseID DoltgresTypeBaseID, str string) string {
31+
switch baseID {
32+
case DoltgresTypeBaseID_Char, DoltgresTypeBaseID_Name, DoltgresTypeBaseID_Text, DoltgresTypeBaseID_VarChar, DoltgresTypeBaseID_Unknown:
33+
return `'` + strings.ReplaceAll(str, `'`, `''`) + `'`
34+
default:
35+
return str
36+
}
37+
}
38+
2739
// truncateString returns a string that has been truncated to the given length. Uses the rune count rather than the
2840
// byte count. Returns the input string if it's smaller than the length. Also returns the rune count of the string.
2941
func truncateString(val string, runeLimit uint32) (string, uint32) {

0 commit comments

Comments
 (0)