Skip to content

fix(sql): error on unknown columns in single-table scope (SQLR-2)#166

Merged
joaoh82 merged 1 commit into
mainfrom
sqlr-2-single-table-unknown-column
Jun 11, 2026
Merged

fix(sql): error on unknown columns in single-table scope (SQLR-2)#166
joaoh82 merged 1 commit into
mainfrom
sqlr-2-single-table-unknown-column

Conversation

@joaoh82

@joaoh82 joaoh82 commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Problem

SingleTableScope::lookup silently returned Value::Null for any column not in the schema (legacy eval_expr behavior), while JoinedScope errors. The ticket framed this as a SELECT-projection cliff, but the projection list was already validated separately — the real surface was expression evaluation:

  • SELECT id FROM t WHERE typo IS NULL silently matched every row
  • …which on UPDATE/DELETE meant a typo'd WHERE mutated or deleted the entire table
  • ORDER BY typo silently no-op'd

Fix

SingleTableScope::lookup now checks contains_column and errors with the same Column '…' does not exist on table '…' message the projection validator uses, matching JoinedScope. A schema column whose cell was never written (omitted from the INSERT column list) still reads as NULL — where_is_null_works_on_omitted_column pins that and still passes. GroupRowScope (HAVING) already errored; no change.

Audit

All 670 pre-existing engine tests pass unmodified — nothing pinned the lenient behavior.

Tests

Four new regression tests (verified to fail with the fix reverted):

  • where_unknown_column_errors_single_table
  • order_by_unknown_column_errors_single_table
  • update_with_unknown_column_in_where_errors_and_mutates_nothing
  • delete_with_unknown_column_in_where_errors_and_deletes_nothing

Full CI matrix green locally (build / test / clippy / doc / fmt with the standard excludes). On-disk REPL smoke: typo'd WHERE statements error cleanly, data intact across reopen.

Docs

Added the WHERE-typo and DELETE-typo cases to docs/smoke-test.md §1.10.

Follow-up

Single-table scope still ignores table qualifiers (SELECT x.id FROM t works) — filed as SQLR issue #14 (qualifier validation needs alias plumbing through every eval_expr callsite).

Refs: SQLR-2, PR #99 (SQLR-5), code review concern #3.

🤖 Generated with Claude Code

SingleTableScope::lookup silently returned Value::Null for any column
not in the schema (legacy eval_expr behavior), while JoinedScope errors.
Net effect: a typo'd column in WHERE silently matched every row — and
on UPDATE/DELETE, mutated or deleted the entire table.

Tighten SingleTableScope::lookup to error on unknown columns, matching
JoinedScope. Schema columns whose cells were never written still read
as NULL (omitted-from-INSERT semantics unchanged). Audit found no
existing test pinning the lenient behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rust-sqlite Ready Ready Preview, Comment Jun 11, 2026 5:05am

Request Review

@joaoh82 joaoh82 merged commit b8617d2 into main Jun 11, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant