Skip to content

[P1][bug] parseSingleParam doesn't extract DEFAULT clauses — default values are lost #395

Closed

Description

@EVWorth

Context

Routine Viewer parses CREATE PROCEDURE/FUNCTION DDL to render parameter inputs.

Problem

src/lib/routine-parser.ts:124-140 (parseSingleParam) splits on /\s+/ and takes [nameIdx + 1 ..] joined as dataType. A parameter like IN p VARCHAR(255) DEFAULT 'foo' parses with name: "p", dataType: "VARCHAR(255)" — DEFAULT 'foo' is dropped — no defaultValue field on RoutineParameter. Worse, IN p VARCHAR(255) DEFAULT CURRENT_TIMESTAMP parses as dataType: "VARCHAR(255)" (the DEFAULT … is consumed as part of the dataType string). When user calls the procedure and leaves param blank, formatParamValue (RoutineViewer.tsx:528-540) sends SET @p = NULL — silently overriding the server-side default. Opposite of what user expects from a procedure with defaults.

Files

  • src/lib/routine-parser.ts:124-140 (parseSingleParam)
  • src/components/routine/RoutineViewer.tsx:528-540 (formatParamValue)

Repro

  1. CREATE PROCEDURE foo(IN x INT DEFAULT 5) BEGIN SELECT x; END
  2. Open Routine Viewer for foo
  3. Leave x blank
  4. Click Execute — @x is NULL, not 5

Expected

CREATE PROCEDURE foo(IN x INT DEFAULT 5) parses with defaultValue: "5". Calling with empty input sends SET @x = 5. The input placeholder shows (default: 5).

Proposed fix

Extend parseSingleParam to scan for DEFAULT keyword after the dataType (handling quoted strings, NULL, numeric, CURRENT_TIMESTAMP). Add defaultValue?: string to RoutineParameter. Extend RoutineViewer.executeProcedure to emit SET @p = ${formatParamValue(val ?? defaultValue ?? "NULL", p.dataType)} — using the default if the input is empty. Extend the input placeholder: placeholder={isReadOnly ? "(output)" : (\Enter ${p.name} (default: ${p.defaultValue})...`)}`. Scope: M.

Acceptance

CREATE PROCEDURE foo(IN x INT DEFAULT 5) parses with defaultValue: "5". Calling with empty input sends SET @x = 5. The input placeholder shows (default: 5).

Needs human verify

yes

Doc drift

no

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/routine
    on Jul 31, 2026
  2. EVWorth commented on Sep 5, 2026

    @EVWorth
    OwnerAuthor

    Closing as invalid — the premise does not hold on either server we support.

    The issue is built on this routine existing:

    CREATE PROCEDURE foo(IN x INT DEFAULT 5) BEGIN SELECT x; END

    Neither MySQL nor MariaDB accepts parameter defaults in a routine declaration:

    MySQL 8.0:    ERROR 1064 (42000): ... check the manual ... near 'DEFAULT 5) BEGIN SELECT x' at line 1
    MariaDB 11:   ERROR 1064 (42000): ... near '' at line 1
    

    Run against the repo's own test containers on ports 13306 and 13308.

    So parseSingleParam can never encounter a DEFAULT clause: a routine carrying one cannot be created, and therefore cannot appear in SHOW CREATE PROCEDURE output. The stated harm — "SET @p = NULL silently overrides the server-side default" — has no server-side default to override.

    Nothing to fix in the parser, and adding a defaultValue field would be dead weight modelling a syntax that does not exist.

    If a dialect we later support does have parameter defaults, this is worth reopening against that dialect specifically.

    Found while verifying premises before starting work on the routine area. The neighbouring #396 turned out to be unreachable for a different reason — executing any procedure that returns rows panics the executor first, which is now #544.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/routineauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions