Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql: create procedure LOOP bug #729

Open
zundaren opened this issue Mar 23, 2024 · 3 comments
Open

mysql: create procedure LOOP bug #729

zundaren opened this issue Mar 23, 2024 · 3 comments
Labels

Comments

@zundaren
Copy link

 label:
 LOOP
        FETCH cur_1 INTO
            event_id,only_code,garage,space;

        IF done THEN
            LEAVE label;
        END IF;

        set @SqlStmtA1 = concat('delete from ', eventtablename, ' where id=', event_id);
        prepare stmtA1 FROM @SqlStmtA1;
        EXECUTE stmtA1;

        COMMIT;
    END LOOP;
    CLOSE cur_1;

image

@zundaren zundaren added the bug label Mar 23, 2024
@nene
Copy link
Collaborator

nene commented Mar 24, 2024

Thanks for reporting.

Unfortunately the support for procedural SQL is pretty much non-existant in SQL-Formatter. Even if it would parse this code without errors, the formatted output would be pretty ugly. Specifically it would be as follows:

label: LOOP FETCH cur_1 INTO event_id,
only_code,
garage,
space;

IF done THEN
LEAVE label;

END IF;

set
  @SqlStmtA1 = concat(
    'delete from ',
    eventtablename,
    ' where id=',
    event_id
  );

prepare stmtA1
FROM
  @SqlStmtA1;

EXECUTE stmtA1;

COMMIT;

END
LOOP;

CLOSE cur_1;

At least I personally wouldn't use it for that.

But yeah, it would be better to not crash.

@fara-nak
Copy link

fara-nak commented Jun 27, 2024

i'm having same issue for:

executeQuery: LOOP
        FETCH something
        Do something
END LOOP executeQuery;

is there any work around or have to uninstall prettier for sql entirely to get rid of this crash?
@nene

@nene
Copy link
Collaborator

nene commented Jun 28, 2024

One pretty ugly workaround is to use MySQL conditional comments:

/*! executeQuery: */ LOOP
        FETCH something
        Do something
END LOOP executeQuery;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants