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

Fix linter for sql query box with multiple statements #19121

Merged
merged 2 commits into from Apr 28, 2024

Conversation

MoonE
Copy link
Contributor

@MoonE MoonE commented Apr 21, 2024

Description

Only change the delimiter for routine/event/trigger editor. The query editor should use the default delimiter.

Fixes #18389, fixes #18487, fixes #18511,

} elseif (! empty($options['eventEditor'])) {
$sqlQuery = 'CREATE EVENT `a` ON SCHEDULE EVERY MINUTE DO ' . $sqlQuery;
$sqlQuery = "DELIMITER $$\nCREATE EVENT `a` ON SCHEDULE EVERY MINUTE DO " . $sqlQuery . '$$';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the $$ at the end?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, multi line content would break otherwise

Copy link
Contributor Author

@MoonE MoonE Apr 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is necessary, In these cases only one statement should be in the editor and a delimiter at the very end is not required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how multiline content would break. I am testing it right now. A delimiter is supposed to delimit two queries apart. If there is no other query appended to it then the delimiter should is redundant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get it to break and it seems to work fine without it. The reported issue is also gone. I think we should merge it without the delimiter at the end. It was needed before because the delimiter was reset back to ; but this is also unnecessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you state versions for the record? "needed before"

Copy link
Member

@williamdes williamdes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you

Always setting the delimiter to $$ is not right in normal sql editor.
This breaks usage of the default delimiter ; and using DELIMITER in the sql.

Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
@MoonE MoonE force-pushed the lint-delimiter branch 2 times, most recently from 758a7db to 3abe6fe Compare April 21, 2024 22:53
@MoonE
Copy link
Contributor Author

MoonE commented Apr 21, 2024

The second commit fixes #18389, the problem was that the annotations were generated for non-existing lines as the linted sql was not the same as the sql in the editor.

With this fixed, linting routines/events/triggers never (except when the sql length exceeds 10000 characters) produces lint results as the body of these statements is not analyzed. It is simply skipped:

Routine: https://github.com/phpmyadmin/sql-parser/blob/011fa18a4e55591fac6545a821921dd1d61c6984/src/Statements/CreateStatement.php#L719-L726
Trigger: https://github.com/phpmyadmin/sql-parser/blob/011fa18a4e55591fac6545a821921dd1d61c6984/src/Statements/CreateStatement.php#L786-L793
Event: https://github.com/phpmyadmin/sql-parser/blob/011fa18a4e55591fac6545a821921dd1d61c6984/src/Statements/CreateStatement.php#L795-L802

So I'm not sure what the reason was for adding the sql prefix in the first place. Wouldn't it work better without it? Parsing the body of these statements as normal sql.

@kamil-tekiela
Copy link
Contributor

So I'm not sure what the reason was for adding the sql prefix in the first place. Wouldn't it work better without it? Parsing the body of these statements as normal sql.

I have asked myself this question this morning too. I suppose there was a scenario which made this fix necessary. It seems to be related to this fix phpmyadmin/sql-parser#438

@williamdes
Copy link
Member

So I'm not sure what the reason was for adding the sql prefix in the first place. Wouldn't it work better without it? Parsing the body of these statements as normal sql.

I have asked myself this question this morning too. I suppose there was a scenario which made this fix necessary. It seems to be related to this fix phpmyadmin/sql-parser#438

That's correct
The parser made changes required in this repo

@williamdes
Copy link
Member

So I'm not sure what the reason was for adding the sql prefix in the first place. Wouldn't it work better without it? Parsing the body of these statements as normal sql.

@Tithugues

Copy link
Member

@williamdes williamdes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good

When the sql string to lint isa changed, the result positions
need to be adjusted accordingly.

Signed-off-by: Maximilian Krög <maxi_kroeg@web.de>
@williamdes williamdes added this to the 5.2.2 milestone Apr 28, 2024
@williamdes williamdes self-assigned this Apr 28, 2024
@williamdes williamdes merged commit 40d5b6d into phpmyadmin:QA_5_2 Apr 28, 2024
29 of 30 checks passed
@MoonE MoonE deleted the lint-delimiter branch April 28, 2024 09:07
williamdes added a commit that referenced this pull request Apr 28, 2024
Signed-off-by: William Desportes <williamdes@wdes.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants