MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / renderQuotedIdent

Function renderQuotedIdent

pkg/sql/parser/pivot.go:33–47  ·  view source on GitHub ↗

renderQuotedIdent reproduces the original delimiters of a quoted identifier token so the parsed value round-trips through the formatter. The tokenizer strips delimiters but records the style in Token.Quote (or, for word tokens, Word.QuoteStyle). Embedded delimiters are escaped per dialect: SQL Serve

(tok models.Token)

Source from the content-addressed store, hash-verified

31// tokens, Word.QuoteStyle). Embedded delimiters are escaped per dialect:
32// SQL Server doubles `]`, ANSI doubles `"`, MySQL doubles “ ` “.
33func renderQuotedIdent(tok models.Token) string {
34 q := tok.Quote
35 if q == 0 && tok.Word != nil {
36 q = tok.Word.QuoteStyle
37 }
38 switch q {
39 case '[':
40 return "[" + strings.ReplaceAll(tok.Value, "]", "]]") + "]"
41 case '"':
42 return "\"" + strings.ReplaceAll(tok.Value, "\"", "\"\"") + "\""
43 case '`':
44 return "`" + strings.ReplaceAll(tok.Value, "`", "``") + "`"
45 }
46 return tok.Value
47}
48
49// parsePivotAlias consumes an optional alias (with or without AS) following a
50// PIVOT/UNPIVOT clause. Extracted to avoid four copies of the same logic in

Callers 2

parsePivotClauseMethod · 0.85
parseUnpivotClauseMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected