phpmyadmin / phpmyadmin/sql-parser

Formatter doesn't handle CASE expressions and statements

Open
#274 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
485
Forks
119
PR merge metrics
No merged PRs in 30d

Description

Formatter doesn't handle CASE expressions and CASE statements.

Related to #272.

Examples:

CASE expression:

-- original
SELECT CASE 1
    WHEN 1 THEN
        'one'
    WHEN 2 THEN
        'two'
    ELSE
        'more'
END;

-- formatted
SELECT CASE
    1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'more'
END;

CASE statement:

-- original
CREATE PROCEDURE p()
BEGIN
    DECLARE
        v INT DEFAULT 1;
    CASE v
        WHEN 2 THEN
            SELECT v;
        WHEN 3 THEN
            SELECT 0;
        ELSE
            BEGIN
            END;
    END CASE;
END;

-- formatted
CREATE PROCEDURE p()
BEGIN
    DECLARE
        v INT DEFAULT 1; CASE v WHEN 2 THEN
    SELECT
        v; WHEN 3 THEN
    SELECT
        0; ELSE
    BEGIN
        END
            ;
    END CASE;
END;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the MySQL CASE expression and CASE statement references, plus the two formatting examples, as the acceptance cases. Compare the current formatter behavior with related issue #272, then locate the formatter entry point and add coverage for both forms; done means each example retains readable CASE and statement clause indentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.