db+grammar: 3d — shortid auto-fill for SQL INSERT (ADR-0033 §6)

When an INSERT's column list omits one or more shortid columns,
the worker now fills them. Command::SqlInsert gains listed_columns
and row_source, captured in build_sql_insert from the matched path
(the row source is located by the first values/select/with Word
token, so a string literal like 'select' can't be mistaken for the
keyword). do_sql_insert calls plan_shortid_autofill, which — per
the user-confirmed Option B — materialises the row source by
running it as a query, generates a distinct shortid per row via the
existing generate_shortid_batch (deduped against stored values),
and reconstructs a parameterised multi-row INSERT over the listed
columns plus the omitted shortid columns. Uniform for VALUES and
INSERT…SELECT, and handles multiple omitted shortids in one row
(each gets its own batch). No explicit list, no omitted shortid, or
a zero-row source → execute verbatim (the 3b path). serial stays
engine-filled via rowid. history.log keeps the original line, never
the rewrite (§11).

Tests: VALUES single/multi-row distinct; explicit override
honoured; INSERT…SELECT distinct fills; combined serial(engine) +
shortid(worker); two shortids (PK + non-PK) both fill; one provided
+ one omitted; compound-PK shortid member; mixed-case column name
(ADR-0009 DA gate); original-source-in-history on the rewrite path.
Still behind the dev `sqlinsert` entry word (3j). 1503 green,
clippy clean.
This commit is contained in:
claude@clouddev1
2026-05-22 07:26:54 +00:00
parent 6ff9144c7a
commit 78ad476d24
5 changed files with 517 additions and 13 deletions
+11 -3
View File
@@ -297,12 +297,20 @@ pub enum Command {
/// the validated statement the worker executes verbatim;
/// `target_table` is extracted from the parse so the worker can
/// re-persist that table's CSV after a successful insert
/// (ADR-0030 §11) without re-parsing the SQL. `listed_columns`
/// (3d, `shortid` auto-fill) and `returning` (3g) are added by
/// the sub-phases that read them.
/// (ADR-0030 §11) without re-parsing the SQL.
///
/// `listed_columns` is the user's explicit `(col, …)` list
/// (empty when the form omits it); `row_source` is the
/// `VALUES …` / `SELECT …` / `WITH … SELECT …` text. Both are
/// captured for sub-phase 3d's `shortid` auto-fill: when the
/// list omits a `shortid` column, the worker materialises the
/// row source, generates fresh ids, and reinserts. `returning`
/// (3g) is added by the sub-phase that reads it.
SqlInsert {
sql: String,
target_table: String,
listed_columns: Vec<String>,
row_source: String,
},
/// App-lifecycle command (per ADR-0003). These work in both
/// simple and advanced modes; the dispatcher branches on the