feat(sql): quote identifiers to prevent reserved word conflicts #1874
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
groups,order,key)Approach
Unlike PR #1856's reserved-word-list approach (260-line hardcoded struct, MySQL-only), this uses always-quote — the same approach used by Hibernate, Doctrine, ActiveRecord, and SQLAlchemy. Benefits:
Changes
New adapter methods:
Base.$quoteIdentifier(name)— no-op default, overridden per adapterBase.$stripIdentifierQuotes(str)— strips quoting chars when parsing rendered SQLMySQLModel.$quoteIdentifier()— wraps with backticksMicrosoftSQLServerModel.$quoteIdentifier()— wraps with bracketsPostgreSQLModel/OracleModel/H2Model/SQLiteModel.$quoteIdentifier()— wraps with double-quotesNew model helpers:
$quotedTableName()— returns table name wrapped in adapter-specific quotes$quoteColumn(column)— wraps a column name in adapter-specific quotesSQL generation updates:
sql.cfc— FROM, DELETE, JOIN, WHERE (key + soft-delete), ORDER BYcreate.cfc— INSERT INTO table and column namesupdate.cfc— UPDATE table and SET column namescalculations.cfc— aggregate SELECT column referencesread.cfc— pagination ORDER BY referencesIdentity select fixes:
$identitySelectimplementations now strip identifier quotes before comparing column listsTest plan
groups,order)Related
Supersedes the approach in #1856 — addresses the same use case (legacy databases with reserved-word identifiers) but implements it for all adapters with a simpler, more maintainable design.
🤖 Generated with Claude Code