formatIdentifier formats an identifier, quoting it if it contains special characters or is a reserved keyword
(ident string)
| 1065 | // formatIdentifier formats an identifier, quoting it if it contains special characters |
| 1066 | // or is a reserved keyword |
| 1067 | func (f *SQLFormatter) formatIdentifier(ident string) { |
| 1068 | if f.needsQuoting(ident) { |
| 1069 | f.builder.WriteString("\"") |
| 1070 | // Escape any existing double quotes by doubling them |
| 1071 | escaped := strings.ReplaceAll(ident, "\"", "\"\"") |
| 1072 | f.builder.WriteString(escaped) |
| 1073 | f.builder.WriteString("\"") |
| 1074 | } else { |
| 1075 | f.builder.WriteString(ident) |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | // needsQuoting returns true if the identifier needs to be quoted |
| 1080 | func (f *SQLFormatter) needsQuoting(ident string) bool { |
no test coverage detected