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
[P0][bug] executeProcedure runs USE + SET + CALL + SELECT @vars as multi-statement SQL — partial apply, identifier interpolation in CALL #394
src/components/routine/RoutineViewer.tsx:115-150 builds sql = "SET @p_in = X; SET @p_out = NULL; CALL proc(@p_in, @p_out); SELECT @p_out AS \p_out`;"and sends via executeQuery. The 4 statements run sequentially on the same pool connection. IfCALL proc() fails mid-execution, the preceding SET statements are committed; the SELECT @p_out doesn't run. No transaction wrapper. Additionally, the multi-statement SQL uses string concatenation: \${database}`.`${routineName}` in the CALL (line 137) and the OUT-param SELECT (line 144) — same escapeId-missing pattern as F1 and compare F4. Editor F7 (resultStore swallows successful results on generation mismatch) interacts: if user cancels mid-CALL, results are dropped but session state committed.
Files
src/components/routine/RoutineViewer.tsx:115-150
Repro
CREATE PROCEDURE foo(IN x INT) BEGIN DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SELECT 'handled'; END
Call foo with IN param that triggers the handler — but the SET statements are already committed
Subsequent calls see stale session vars
Expected
A procedure that raises mid-execution leaves no @vars committed. IN param value ' OR 1=1 -- is escaped as a literal value, not interpreted as SQL. Parameter binding round-trips.
Proposed fix
Add a Tauri command execute_routine_procedure(connection_id, database, routine_name, params: Vec<RoutineParamValue>) -> ProcedureResult { result_sets, out_params, execution_time_ms }. Backend wraps SET + CALL in sqlx::Transaction<'_, MySql> and commits only on full success; reads OUT params via a final SELECT @p_out …; binds IN values via ? placeholders with Vec typing (depends on editor F5 parameterized queries). Frontend executeProcedure calls this command and unwraps ProcedureResult into the existing UI state. Scope: L.
Acceptance
A procedure that raises mid-execution leaves no @vars committed. IN param value ' OR 1=1 -- is escaped as a literal value, not interpreted as SQL. Parameter binding round-trips.
Verified the premise before implementing, and part of it does not hold.
The transaction proposal cannot work
The proposed fix is to wrap SET + CALL in a sqlx::Transaction and commit only on success, with the acceptance criterion:
A procedure that raises mid-execution leaves no @vars committed.
Session variables are not transactional. Against MySQL 8:
SET @a =1;
START TRANSACTION;
SET @a =2;
ROLLBACK;
SELECT @a; -- 2
ROLLBACK does not restore @a. A transaction around the batch would roll back any data the routine wrote, but the SET @p_in = ... statements would stand regardless. The stated acceptance cannot be met by that design, so implementing it would produce a change that looks like a fix and is not one.
The practical harm is also smaller than described
The repro says "subsequent calls see stale session vars". executeProcedure re-initialises every parameter before each CALL, including OUT params set to NULL, so a stale value from a previous run is always overwritten before it can be read. For staleness to be observable, one of the SET statements would itself have to fail — and the next run would re-set it anyway.
I am not claiming there is no ordering hazard here, only that the "stale vars corrupt the next call" mechanism as written does not reproduce.
parameter values go through quoteStringLiteral — the old ' → \' escape left backslashes alone, so \' OR 1=1 -- broke out of the literal. Demonstrated against MySQL 8 (details in the PR).
identifiers in the CALL and the OUT-param SELECT go through quoteIdentifier
parameter names are checked against a plain-identifier pattern, since SET @name takes the name unquoted and offers nothing to escape with
What is left on this issue
Two things worth keeping open, both narrower than the original scope:
Partial apply is still possible — a failing CALL leaves the preceding SETs applied. Given the above, the fix is not a transaction; it would be either building the argument list inline in the CALL so no session variables are needed for IN parameters, or accepting the behaviour and documenting it. The first is probably right and is a much smaller change than a new Tauri command.
A CALL on a production connection is not gated.isDestructiveStatement covers DROP/DELETE/TRUNCATE/ALTER/RENAME/GRANT/REVOKE/KILL/FLUSH/SHUTDOWN and some phrases — not CALL. A procedure that deletes rows runs on production with no prompt. Whether every CALL should prompt is a product decision rather than a bug fix, so I have not made it unilaterally.
Retitling suggestion: this is no longer "runs as multi-statement SQL — partial apply, identifier interpolation". The interpolation half is done; what remains is (1) above.
Fixed the parts that were real, rejected the transaction, and found something the issue did not mention. #653.
The identifier interpolation is gone — the CALL and the OUT-param SELECT go through quoteIdentifier, with a test using a database called odd`db. Your ' OR 1=1 -- case was checked live against MySQL 8.0.46 and MariaDB 11.8: the procedure receives it as data and stores it as data.
Found while looking: the call was overwriting the user's own session variables. Parameters were passed as @name, on the connection the editor also uses. A procedure with a parameter called x silently replaced whatever the user had put in @x, with nothing anywhere to say it had happened. They now go through @sqlpilot_param_<name>.
The batch moved out of the component into buildProcedureBatch, so what gets sent can be read and tested instead of being assembled across forty lines of JSX. Nine tests on it.
The transaction
Rejecting it, on three grounds.
Session variables are not transactional.ROLLBACK does not restore a @var — there is nothing to commit and nothing to undo. "A procedure that raises mid-execution leaves no @vars committed" is not a state MySQL has.
The repro cannot happen. "Subsequent calls see stale session vars" — every execution sets all of them before the CALL, including the OUT ones, which are explicitly set to NULL. There is no path where a previous call's value survives into the next.
Wrapping the CALL would be wrong. Procedures routinely manage their own transactions; START TRANSACTION inside one either raises or implicitly commits depending on what it does. Neither DBeaver nor Workbench wraps a CALL — the procedure's transaction semantics belong to its author, and a client that quietly changes them is worse than one that does not.
On the fourth part — "the 4 statements run sequentially on the same pool connection" — that is not an accident, it is the mechanism. The executor sends a batch as a single raw_sql, which is what makes the session variables set by the first statements visible to the CALL. Sent separately they could land on a session where the SETs never ran. There is now a test pinning that they stay one batch, so nobody splits them later thinking it is tidier.
The proposed execute_routine_procedure command with bound parameters is not reachable either: a CALL's arguments can be placeholders, but OUT parameters have to be session variables — the protocol has no other way to read one back. That is why mysql(1) and every client does it this way.
Activity
EVWorth commentedon Sep 5, 2026
Verified the premise before implementing, and part of it does not hold.
The transaction proposal cannot work
The proposed fix is to wrap SET + CALL in a
sqlx::Transactionand commit only on success, with the acceptance criterion:Session variables are not transactional. Against MySQL 8:
ROLLBACKdoes not restore@a. A transaction around the batch would roll back any data the routine wrote, but theSET @p_in = ...statements would stand regardless. The stated acceptance cannot be met by that design, so implementing it would produce a change that looks like a fix and is not one.The practical harm is also smaller than described
The repro says "subsequent calls see stale session vars".
executeProcedurere-initialises every parameter before eachCALL, including OUT params set to NULL, so a stale value from a previous run is always overwritten before it can be read. For staleness to be observable, one of theSETstatements would itself have to fail — and the next run would re-set it anyway.I am not claiming there is no ordering hazard here, only that the "stale vars corrupt the next call" mechanism as written does not reproduce.
What was real, and is now fixed
The injection half. #543 closes it:
quoteStringLiteral— the old'→\'escape left backslashes alone, so\' OR 1=1 --broke out of the literal. Demonstrated against MySQL 8 (details in the PR).CALLand the OUT-paramSELECTgo throughquoteIdentifierSET @nametakes the name unquoted and offers nothing to escape withWhat is left on this issue
Two things worth keeping open, both narrower than the original scope:
CALLleaves the precedingSETs applied. Given the above, the fix is not a transaction; it would be either building the argument list inline in theCALLso no session variables are needed for IN parameters, or accepting the behaviour and documenting it. The first is probably right and is a much smaller change than a new Tauri command.CALLon a production connection is not gated.isDestructiveStatementcovers DROP/DELETE/TRUNCATE/ALTER/RENAME/GRANT/REVOKE/KILL/FLUSH/SHUTDOWN and some phrases — notCALL. A procedure that deletes rows runs on production with no prompt. Whether everyCALLshould prompt is a product decision rather than a bug fix, so I have not made it unilaterally.Retitling suggestion: this is no longer "runs as multi-statement SQL — partial apply, identifier interpolation". The interpolation half is done; what remains is (1) above.
fix(routine): close the parameter injection, and put DROP behind the …
EVWorth commentedon Sep 12, 2026
Fixed the parts that were real, rejected the transaction, and found something the issue did not mention. #653.
The identifier interpolation is gone — the CALL and the OUT-param SELECT go through
quoteIdentifier, with a test using a database calledodd`db. Your' OR 1=1 --case was checked live against MySQL 8.0.46 and MariaDB 11.8: the procedure receives it as data and stores it as data.Found while looking: the call was overwriting the user's own session variables. Parameters were passed as
@name, on the connection the editor also uses. A procedure with a parameter calledxsilently replaced whatever the user had put in@x, with nothing anywhere to say it had happened. They now go through@sqlpilot_param_<name>.The batch moved out of the component into
buildProcedureBatch, so what gets sent can be read and tested instead of being assembled across forty lines of JSX. Nine tests on it.The transaction
Rejecting it, on three grounds.
ROLLBACKdoes not restore a@var— there is nothing to commit and nothing to undo. "A procedure that raises mid-execution leaves no @vars committed" is not a state MySQL has.START TRANSACTIONinside one either raises or implicitly commits depending on what it does. Neither DBeaver nor Workbench wraps a CALL — the procedure's transaction semantics belong to its author, and a client that quietly changes them is worse than one that does not.On the fourth part — "the 4 statements run sequentially on the same pool connection" — that is not an accident, it is the mechanism. The executor sends a batch as a single
raw_sql, which is what makes the session variables set by the first statements visible to the CALL. Sent separately they could land on a session where the SETs never ran. There is now a test pinning that they stay one batch, so nobody splits them later thinking it is tidier.The proposed
execute_routine_procedurecommand with bound parameters is not reachable either: a CALL's arguments can be placeholders, but OUT parameters have to be session variables — the protocol has no other way to read one back. That is why mysql(1) and every client does it this way.