Repository navigation
Description
Context
Routine Viewer procedure execute extracts OUT param values from the final SELECT result.
Problem
src/components/routine/RoutineViewer.tsx:158-185 extracts outParamResults from queryResults[queryResults.length - 1] — assumes the last SELECT in the multi-statement SQL is the OUT-param SELECT (which executeProcedure does append, line 144-147). But: (a) the results state is set with the full queryResults array (line 153), so the Results section renders all sets — good. (b) outParamResults reads only the last set. A procedure that returns SELECT 'hello' AS greeting; SELECT 'val' AS p_out; would show outValue: 'hello' for p_out — wrong. The lastResult.columns[i].name is used as the key, so a procedure returning SELECT @p_out AS \p_out`; SELECT 'done'would correctly pick p_out from the second set, but a procedure returningSELECT 'greeting'; SELECT @p_out AS `p_out`` (the bug case) maps by col.name — if the greeting set's column is named greeting and the out set's column is named p_out, then outParamResults would have only p_out mapped (correct) — but only because of the column-name match. Bug is real when the procedure's own SELECT has different column names than the OUT param column names.
Files
- src/components/routine/RoutineViewer.tsx:158-185 (outParamResults extraction)
Repro
- CREATE PROCEDURE foo(IN x INT) BEGIN SELECT 'hello' AS greeting; SET @p_out = x + 1; END
- Call foo — executeProcedure appends
SELECT @p_out AS \p_out`` - queryResults = [{columns: [greeting], rows: [['hello']]}, {columns: [p_out], rows: [[5]]}]
- outParamResults picks last set → p_out = 5 (correct for this case because column names differ)
- If a procedure returns SELECT 'hello'; SELECT @p_out AS `p_out` with same column 'greeting' as the OUT-param SELECT, it gets confused
Expected
A procedure returning SELECT 'hello' AS greeting; SELECT @p_out AS \p_out`;` shows greeting: 'hello' in the Results section AND p_out: '' in the OUT params input.
Proposed fix
Tag the OUT-param SELECT with a sentinel column name prefix (e.g., SELECT @p_out AS \__out__p_out``) and filter queryResults for the set containing out columns. Or, simpler: append the OUT-param SELECT with UNION ALL markers and detect. Cleanest fix: the backend command (F2) returns a typed ProcedureResult { result_sets: Vec, out_params: HashMap<String, String> } — out_params is computed server-side, no ambiguity. Scope: M.
Acceptance
A procedure returning SELECT 'hello' AS greeting; SELECT @p_out AS \p_out`;` shows greeting: 'hello' in the Results section AND p_out: '' in the OUT params input.
Needs human verify
yes
Doc drift
no
Activity
fix(query): stop assuming one result set per statement, which CALL br…
EVWorth commentedon Sep 5, 2026
Re-examined now that #544 is fixed, and this does not reproduce.
It could not be reached before
Executing any procedure that returns rows panicked the executor (#544, fixed in #545), so the OUT-param extraction never ran at all.
With that fixed, the extraction is correct
The batch
executeProcedurebuilds now comes back attributed like this, verified against MySQL 8:The appended
SELECT @p_outis a separate statement issued after theCALLreturns, so its result set is always last. ReadingqueryResults[queryResults.length - 1]therefore always reads the OUT-param set.Including the collision case the issue calls out
The issue's worst case is a procedure whose own
SELECTemits a column named the same as the OUT parameter. Built and ran exactly that:The OUT parameter reads back as
99. The name collision does not matter, because the selection is positional and the position is always right.The issue text is self-aware about this — it works through the example and concludes "correct for this case because column names differ", then supposes a variant that cannot occur, since the appended
SELECT's column name is the OUT parameter's own name.One real thing nearby, not worth reopening for
The appended
SELECT @p_outshows up as a visible result tab alongside the procedure's own output. That is noise rather than a wrong answer — the user sees an extra tab containing the value already displayed in the OUT params box. Mentioning it rather than filing it; say the word if it is worth its own issue.Closing as not reproducible.