fix(sql): validate table qualifiers in single-table scope (SQLR-14)#167
Merged
Conversation
SingleTableScope now carries the user-visible scope name (FROM alias when declared, else the table name) and rejects any other qualifier with the same unknown-table-qualifier error JoinedScope produces. Validation covers the projection list, WHERE (including the index-probe shape, which previously stripped the qualifier via parts.last()), ORDER BY, GROUP BY keys, aggregate args, and UPDATE SET right-hand sides. UPDATE / DELETE now plumb their FROM alias through extract_table_name, so alias forms validate too — and per SQLite semantics a declared alias shadows the table name as a qualifier. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fixes SQLR-14:
SingleTableScopeignored table qualifiers entirely, soSELECT x.id FROM t,... WHERE bogus.id = 1, and the UPDATE/DELETE equivalents silently resolvedanything.colas plaincol.JoinedScopealready errored on unknown qualifiers; the single-table path now matches it (and SQLite).Changes
SingleTableScopecarries ascope_name(FROM alias when declared, else table name) andlookuprejects mismatched qualifiers withJoinedScope's exact wording:unknown table qualifier 'x' in column reference 'x.id'. Matching is ASCII case-insensitive.check_single_scope_qualifierhelper also guards the schema-level checks that run before any row is visited: projection list, GROUP BY keys, aggregate args — and the index-probe WHERE shape, wheretry_extract_equalitypreviously stripped the qualifier viaparts.last()(soWHERE bogus.name = 'x'on an indexed column bypassed evaluation entirely).eval_predicate/eval_expr/sort_rowids/select_topk/select_rowidstake the scope name;extract_table_namenow returns the FROM alias, so UPDATE / DELETE validate too (WHERE and UPDATE SET right-hand sides, includingUPDATE t AS a …/DELETE FROM t AS a …).SELECT t.id FROM t AS aerrors — pinned by tests for SELECT, UPDATE, and DELETE.docs/sql-engine.md; added a qualified-references bullet todocs/supported-sql.md.Acceptance criteria
SELECT t.id FROM tandSELECT a.id FROM t AS akeep working (case-insensitive)SELECT x.id FROM terrors withJoinedScope-consistent wordingUPDATE t SET ... WHERE x.id = 1errors)SELECT t.id FROM t AS aerrors), matching SQLite — pinned with testsTesting
cargo fmt --check,cargo clippy,cargo docclean — warning sets identical tomain(verified by stash-diff)Known gaps (follow-ups, not in this PR)
fts_match(bogus.col, …)/bm25_scoreextract their column arg syntactically and still strip a qualifier silently (function args need scope-name access ineval_function)HAVING x.dept …ignores qualifiers viaGroupRowScope— shared with the joined path, so single-table and JOIN behavior remain consistent there🤖 Generated with Claude Code