You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[P1] [bug] extractTableName catches wrong table for JOINs/CTEs — silent corruption on Save #399
[P1] [bug] extractTableName regex catches wrong table for JOINs/CTEs/subqueries — silent data corruption on Save
Context
The grid's handleSave calls extractTableName(sql) to derive the table for UPDATE/INSERT/DELETE generation. The regex only matches the first FROM clause.
Problem
Per docs/audits/results.md F6.
SELECT u.* FROM users u JOIN orders o ON u.id = o.user_id WHERE o.id = 42 returns users but the user filtered by orders and probably wants to edit the orders row. CTE/subquery forms (WITH cte AS ..., SELECT * FROM (SELECT ...) t) return the wrong name or fail. Multi-statement scripts always pick the first FROM. Save generates UPDATE against the wrong table — silent data corruption.
Files
src/lib/sql-generator.ts:60-67
src/components/grid/ResultsGrid.tsx:243-258
Repro (if applicable)
Static analysis only.
Expected
Either (a) confirm table before Save via modal "Apply changes to table X?", or (b) parse with a real SQL parser that handles JOINs/CTEs/subqueries.
Proposed fix
Scope M. Option (a) is the safer interim: confirm modal with detected table + dropdown to override.
Acceptance
A JOIN query shows the modal with the user-selected table; UPDATE is generated against the confirmed table.
Fixed by #529 (commit dc1f76c). extractTableName was replaced with resolveEditTarget in src/lib/sql-generator.ts, which refuses joins (both syntaxes), CTEs, UNION, subquery-in-FROM, GROUP BY/DISTINCT, multi-statement and non-SELECT rather than guessing a table from the first FROM clause. It errs towards refusing: a query it wrongly declines is an inconvenience, one it wrongly accepts is a silent write to the wrong table.
Not auto-closed because the PR body wrote Refs #399 rather than a closing keyword.
Activity
fix(grid): write edits to the right table, addressed by the real key (#…
EVWorth commentedon Sep 4, 2026
Fixed by #529 (commit dc1f76c).
extractTableNamewas replaced withresolveEditTargetin src/lib/sql-generator.ts, which refuses joins (both syntaxes), CTEs, UNION, subquery-in-FROM, GROUP BY/DISTINCT, multi-statement and non-SELECT rather than guessing a table from the first FROM clause. It errs towards refusing: a query it wrongly declines is an inconvenience, one it wrongly accepts is a silent write to the wrong table.Not auto-closed because the PR body wrote
Refs #399rather than a closing keyword.