Documentation
¶
Index ¶
- Constants
- Variables
- func HasUnescapedQuote(text string) bool
- func IsBareIdentifier(s string) bool
- func IsOracleReservedWord(word string) bool
- func IsQuotedIdentifier(text string) bool
- func IsQuotedString(s string) bool
- func IsUnquotedIdentifier(s string) bool
- func QuoteIdentifierLiteral(text string) string
- func QuoteOracleIdentifier(column string) string
- func SplitIdentifierSegments(identifier string) []string
- func ValidateSegment(segment string) bool
Constants ¶
const ( // IdentifierSegment is a single unquoted identifier: a leading letter or // underscore followed by letters, digits, underscore, $ or # — the same // alphabet enforced for db-tag struct fields by the columns package. IdentifierSegment = `[A-Za-z_][A-Za-z0-9_$#]*` // Segment matches either form. Segment = `(?:` + IdentifierSegment + `|` + quotedSegment + `)` )
The SQL identifier grammar every door validates an identifier argument against before it becomes SQL syntax (ADR-031, ADR-082). It lives here because two packages judge against it — the query builder and the columns package — and the builder imports the columns package, so neither can own it without a cycle.
Variables ¶
var OracleReservedWords = map[string]struct{}{ // contains filtered or unexported fields }/* 109 elements not displayed */
OracleReservedWords contains all Oracle SQL reserved keywords that require double-quote quoting when used as identifiers (column names, table names, etc.).
This is the canonical source of truth for Oracle reserved word detection across the GoBricks framework. Both the query builder and column parser rely on this list for automatic identifier quoting.
The map is kept in parity with the full official Oracle 19c reserved-word list (V$RESERVED_WORDS where reserved='Y'); parity is enforced by TestOracleReservedWordsMatchOfficial19cList. A small, intentional superset is also quoted defensively (BEGIN, CASE, WHEN, EXCLUDE) — see that test for the rationale of each entry.
Source: Oracle Database SQL Language Reference 19c, "Oracle SQL Reserved Words". https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Oracle-SQL-Reserved-Words.html
Note: This list uses struct{} for zero-memory overhead in the map value.
Functions ¶
func HasUnescapedQuote ¶ added in v0.61.0
HasUnescapedQuote reports whether text carries a quote that is not part of a doubled "" escape. It reads renderings only: the builder's upsert door judges the KEY with its stricter keyCarriesInteriorQuote check — a rendering may legitimately carry a doubled quote, a caller's identifier argument may not.
func IsBareIdentifier ¶ added in v0.60.0
IsBareIdentifier reports whether s is a single identifier segment — unquoted, or in the framework's own quoted reserved-word form (`"level"`). This is the grammar the table argument already applies to the alias half of "users u".
The check is deliberately not preceded by a trim: a caller's value is judged exactly as it will be interpolated, so validating a trimmed value while rendering the untrimmed one cannot let the two disagree (ADR-082).
func IsOracleReservedWord ¶
IsOracleReservedWord checks if a word is an Oracle reserved keyword. The check is case-insensitive since Oracle identifiers are case-insensitive by default.
Examples:
IsOracleReservedWord("LEVEL") // true
IsOracleReservedWord("level") // true
IsOracleReservedWord("Level") // true
IsOracleReservedWord("user_id") // false
func IsQuotedIdentifier ¶ added in v0.61.0
IsQuotedIdentifier reports whether text is ALREADY a well-formed quoted identifier: wrapped in quotes with every interior quote doubled. Re-quoting one of these would change the name it denotes, which is why the renderers pass it through. Wrapping alone does not qualify — `role" = 'admin', "name` is wrapped and is two SQL tokens.
func IsQuotedString ¶ added in v0.61.0
IsQuotedString reports whether a string is fully enclosed in double quotes.
func IsUnquotedIdentifier ¶ added in v0.61.0
IsUnquotedIdentifier reports whether s is a single UNQUOTED identifier segment. It differs from IsBareIdentifier in rejecting the quoted reserved-word form (`"level"`), for the doors where a quoted spelling has no meaning — an expression alias is one: the framework never emits a quoted alias, so accepting one would widen the grammar for caller-supplied text alone.
Like IsBareIdentifier it does not trim: the value is judged exactly as it will be interpolated (ADR-082).
func QuoteIdentifierLiteral ¶ added in v0.61.0
QuoteIdentifierLiteral wraps text in quotes with every interior quote doubled, which is how Oracle and PostgreSQL both spell a quote inside a name. A quote left undoubled ends the identifier early, so the remainder is parsed as SQL.
Collapsing precedes doubling because a key arrives in escaped form: `a""b` already denotes the one-quote name `a"b`, the reading the upsert door applies to it. Doubling blind would rename that column. Collapsing first makes the pass idempotent — an already-escaped key survives unchanged, and a lone quote is the only thing that gains a partner.
func QuoteOracleIdentifier ¶ added in v0.61.0
QuoteOracleIdentifier applies Oracle's quoting rules to an identifier: qualified names are split on separator dots and each segment quoted on its own (#1151), an already-quoted segment passes through unchanged, and a segment that is a reserved word or falls outside the bare-identifier alphabet is wrapped with its interior quotes doubled (#1104).
func SplitIdentifierSegments ¶ added in v0.61.0
SplitIdentifierSegments splits a qualified identifier on the dots that SEPARATE segments, leaving a dot inside a quoted segment where it belongs: `"my.col"` is one column, not two (#1151). Both identifier renderers compose it the same way, so the fallback rule lives here once rather than at each.
A string parseQualifiedIdentifier rejects — unbalanced quotes — comes back as a single segment. Rendering fewer segments than the caller wrote would be the silent variant; one whole (escaped) identifier is not.
func ValidateSegment ¶ added in v0.61.0
ValidateSegment checks if a segment is valid (quoted or unquoted); an empty segment is invalid.
Types ¶
This section is empty.