MCPcopy Create free account
hub / github.com/dolthub/doltgresql / EncodeEscapedSQLIdent

Function EncodeEscapedSQLIdent

postgres/parser/lex/encode.go:176–195  ·  view source on GitHub ↗

EncodeEscapedSQLIdent writes the identifier in s to buf. The identifier is always quoted. Double quotes inside the identifier are escaped.

(buf *bytes.Buffer, s string)

Source from the content-addressed store, hash-verified

174// identifier is always quoted. Double quotes inside the identifier
175// are escaped.
176func EncodeEscapedSQLIdent(buf *bytes.Buffer, s string) {
177 buf.WriteByte('"')
178 start := 0
179 for i, n := 0, len(s); i < n; i++ {
180 ch := s[i]
181 // The only character that requires escaping is a double quote.
182 if ch == '"' {
183 if start != i {
184 buf.WriteString(s[start:i])
185 }
186 start = i + 1
187 buf.WriteByte(ch)
188 buf.WriteByte(ch) // add extra copy of ch
189 }
190 }
191 if start < len(s) {
192 buf.WriteString(s[start:])
193 }
194 buf.WriteByte('"')
195}
196
197// EncodeLocaleName writes the locale identifier in s to buf. Any dash
198// characters are mapped to underscore characters. Underscore characters do not

Callers 2

EncodeRestrictedSQLIdentFunction · 0.85

Calls 1

WriteStringMethod · 0.80

Tested by

no test coverage detected