fix: INSERT Form B value-count UX (ADR-0033 Amendment 5)
Three layered fixes for advanced/simple-mode positional INSERT
value-count mismatches (e.g. `insert into T values (...)` with the
wrong number of values for T's column count), plus ADR-0033
Amendment 5 recording the gate refinement.
Walker diagnostic (dml_insert_arity_diagnostics): the function's own
doc-comment recorded the no-column-list (Form B) case as deferred.
This commit closes that gap. Form B mismatches now emit a new
diagnostic.insert_arity_mismatch_form_b ERROR per offending tuple,
keyed off the target table's column count from the schema cache. The
[ERR] validity indicator (ADR-0027) lights up at typing time for the
reported scenario, no longer needing a submit.
Cross-mode pointer gate (advanced_alternative_note): refactored from
a hand-rolled Form B count check to a single input_verdict_in_mode(
input, schema, Mode::Advanced) call. The pointer fires only when the
verdict is None — the ADR-0027 sense of "valid". Any future static
check added to the verdict pipeline participates automatically; no
per-feature maintenance.
Teaching notes for the value-count cases users can hit before the
indicator turns red:
- simple-mode submit: insert.form_b_extra_values_note covers under-,
in-window, and over-supply against the Form B contract; suppressed
when the cross-mode pointer fires (to avoid parallel advice).
- advanced-mode dispatch pre-flight:
insert.form_b_positional_count_mismatch_note catches a submitted
mismatch with a teaching message before the engine produces its
raw NOT-NULL / type error.
The advanced_mode.also_valid_sql pointer wording was reworked to
"trying to write SQL? switch with `mode advanced`, or prefix `:` to
run once". One insta snapshot regenerated.
ADR-0033 Amendment 5 records the gate change: Amendment 3's "would
parse in advanced mode" now reads as "valid in advanced mode" in the
explicit verdict-is-None sense, with the precise definition spelled
out so future readers can't drift back to the syntactic-only reading.
ADR-0000 index entry updated; docs/requirements.md H1a citation added
listing the three new pedagogical strings.
Tests added (8): four walker arity tests (under-supply, over-supply,
match, unknown-table); two app-level teaching-note tests for the
sibling cases (under-supply, over-supply beyond total); one pointer-
gate unit test pinning the bug-case suppression; one gate-precedence
test ensuring only one advice line per error. Existing
simple_mode_submit_of_sql_construct_appends_advanced_pointer updated
to use a known schema (the new validity gate requires it).
Full suite: 2031 passed, 0 failed, 0 unexpected skips. Clippy clean.
This commit is contained in:
@@ -573,6 +573,8 @@ diagnostic:
|
||||
# ADR-0033 §8 — Phase-3 DML diagnostic keys.
|
||||
auto_column_overridden: "column `{column}` is auto-generated (`{type}`); providing an explicit value bypasses the auto-counter and may collide with later auto-generated values"
|
||||
insert_arity_mismatch: "the column list names {expected} column(s) but {actual} value(s) are given"
|
||||
# ADR-0033 §8.1 / Amendment 5: Form B (no column list) variant.
|
||||
insert_arity_mismatch_form_b: "with no column list, all {expected} column(s) need a value but {actual} value(s) are given"
|
||||
not_null_missing: "column `{column}` is required (`NOT NULL`, no default); the statement will fail when run"
|
||||
|
||||
# Engine-error translations: an engine-rejected SQL statement
|
||||
@@ -705,8 +707,22 @@ advanced_mode:
|
||||
sql_in_simple: "`{command}` is SQL — available in advanced mode. Switch with `mode advanced`, or prefix the line with `:` to run it once."
|
||||
# Appended to a simple-mode DSL error when the same line would run
|
||||
# in advanced mode — keeps the actionable DSL fix and adds the mode
|
||||
# pointer (ADR-0033 Amendment 3).
|
||||
also_valid_sql: "(valid as SQL in advanced mode — `mode advanced` or prefix `:`)"
|
||||
# pointer (ADR-0033 Amendment 3). Suppressed by `advanced_alternative_note`
|
||||
# for cases the advanced engine would also reject (issue #1).
|
||||
also_valid_sql: "(trying to write SQL? switch with `mode advanced`, or prefix `:` to run once)"
|
||||
|
||||
# ---- Insert education hints (issue #1 sub-task 2) -------------------
|
||||
# Appended to a simple-mode INSERT Form B parse error when the user
|
||||
# supplied more values than Form B's non-auto-generated columns expect
|
||||
# (but not more than every column). Teaches the contract that excludes
|
||||
# `serial` / `shortid` columns and points at the column-list form.
|
||||
insert:
|
||||
form_b_extra_values_note: "`insert into {table} values (…)` expects {expected_phrase} — {auto_phrase}. To set them explicitly, list every column: `insert into {table} ({all_cols}) values (…)`."
|
||||
# Pre-flight teaching note for advanced-mode positional
|
||||
# `INSERT INTO T VALUES (…)` (no column list) when the value count
|
||||
# doesn't match the column count (issue #1 sub-task 3). The override
|
||||
# uses the non-auto columns so the user can omit serial/shortid.
|
||||
form_b_positional_count_mismatch_note: "Positional `insert into {table} values (…)` requires a value for every column. `{table}` has {col_count} columns ({col_list}); you supplied {supplied}. To omit auto-generated columns, list the columns you want: `insert into {table} ({non_auto_csv}) values (…)`."
|
||||
|
||||
# ---- SQL SELECT (advanced mode; ADR-0030 / ADR-0031) ----------------
|
||||
select:
|
||||
|
||||
Reference in New Issue
Block a user