Skip to content

fix(routine): validate parameters where they are typed - #653

Merged
EVWorth merged 3 commits into
mainfrom
fix/routine-params
Sep 12, 2026
Merged

EVWorth merged 3 commits into
mainfrom
fix/routine-params

Conversation

@EVWorth

@EVWorth EVWorth commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Closes #398, #397, #394.

A mistyped number was sent as NULL (#398)

Numeric parameters used type="number". A number input reads back "" for anything the browser cannot parse, and this dialog sends an empty value as NULL — so a mistyped id became a call with no id rather than an error. Its spinner also rounds a BIGINT past 2^53, which is the precision that type exists for.

Exact numerics now get a text box with inputMode="numeric", so the value the user typed is the value that gets checked. And the check runs as they type: the same formatParamValue the execute path uses, with the reason under the input, aria-invalid on it, and Execute disabled while any value is wrong — your acceptance criterion. There is a test asserting the two agree on a range of inputs, so Execute can never be disabled for a value that would have worked, or enabled for one that will not.

The session variables were the user's own (#394)

Parameters were passed as @name, on the connection the editor also uses. A procedure with a parameter called x silently overwrote whatever the user had put in @x, with nothing in the editor to say so. They now go through @sqlpilot_param_<name>.

The batch moved into buildProcedureBatch, so what is sent can be read and tested rather than assembled inline across forty lines of component.

What I did not do, and why. The issue asks for the SET + CALL to be wrapped in a transaction so a procedure that raises leaves no @vars committed.

  • Session variables are not transactional. ROLLBACK does not restore a @var; there is nothing to commit or undo. The stated repro — "subsequent calls see stale session vars" — cannot happen either: every execution sets all of them before the CALL.
  • Wrapping the CALL itself would be wrong. Procedures routinely manage their own transactions, and START TRANSACTION inside one raises or implicitly commits depending on what it does. Neither DBeaver nor Workbench wraps a CALL; the procedure's transaction semantics are its author's.
  • The four statements already run on one connection: the executor sends a batch as a single raw_sql, which is what makes the session variables reachable by the CALL at all. There is a test pinning that they stay one batch.

The identifier interpolation the issue names was fixed earlier — the CALL and the OUT-param SELECT go through quoteIdentifier, and there is a test with a database called odd`db.

#397 was already fixed; verified rather than assumed

formatParamValue doubles the quote and refuses what a type cannot hold, and buildFunctionCall quotes both identifiers. Checked live on MySQL 8.0.46 and MariaDB 11.8: a procedure called with a' OR 1=1 -- receives it as data and stores it as data; f_in('don''t') returns fn:don't. Tests pin both shapes.

Tests

+22 (9 for the batch, 6 for the inline validation in the component, 7 for the validator and the variable naming). 2692 unit, 344 browser, tsc and eslint clean.

clobbering the user's session variables

Three things, from the routine audit.

A mistyped number was sent as NULL. Numeric parameters used
`type="number"`, and a number input reads back "" for anything the
browser cannot parse — which this dialog sends as NULL. So a mistyped id
became a call with no id rather than an error, and the spinner rounded a
BIGINT past 2^53, which is the precision the type exists for. Exact
numerics now get a text box with a numeric keypad, so the value the user
typed is the value that is checked.

That check now runs as they type: the same `formatParamValue` the
execute path uses, with the reason shown under the input and Execute
disabled while any value is wrong. It used to be an error after
clicking. A test asserts the two agree, so Execute can never be disabled
for a value that would have worked, or enabled for one that will not.

Calling a procedure overwrote the user's own session variables. The
parameters were passed as `@name`, on the connection the editor also
uses, so a procedure with a parameter called `x` silently replaced
whatever was in `@x`. They go through `@sqlpilot_param_<name>` now.

The batch itself moved out of the component into `buildProcedureBatch`,
so what is sent to the server can be read and tested rather than being
assembled inline across forty lines.

+22 tests. The hostile-value case was checked against MySQL 8.0.46 and
MariaDB 11.8: the procedure receives `a' OR 1=1 -- ` as data.
… theme

Six drops asked with window.confirm — the routine viewer's, and the
schema tree's view, procedure, function, trigger and event. That dialog
is unstyled, blocks the whole window, and cannot be tested without
stubbing a global. They now use the app's own dialog, which the
production guard already had.

On a production connection it does not ask twice: the drop runs through
resultStore, whose production gate raises its own dialog naming the
statement, and that is the stronger of the two.

The routine viewer's DDL panel hardcoded theme="vs-dark", so on a light
theme it was the only black rectangle on the screen.

Routine audit F7 and F9.
`RETURNS varchar(80) CHARSET utf8mb4` — which is what MySQL's own SHOW
CREATE FUNCTION prints — showed as `varchar(80)`. A function returning
utf8mb4 is a different function from one returning latin1, and the badge
hid the difference. COLLATE and the CHARACTER SET spelling too.

Routine audit F8. +5 tests, shapes taken from a live server's output.
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.

[P1][bug] formatParamValue returns invalid SQL for typed input that fails numeric/date parsing

1 participant