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 way end of functions, procedures and triggers' bodies is identified #438

Merged
merged 2 commits into from
Apr 14, 2023

Conversation

Tithugues
Copy link
Contributor

@williamdes reported that

public function testParsephpMyAdminDump(): void
was incorrect.
Indeed, in this file https://github.com/phpmyadmin/sql-parser/blob/4bfd15c40c6e7cec3592095cd405f52931af1b10/tests/data/parser/parsephpMyAdminExport1.in, the variables defined in the last comments where not reported (as we can see in the unit test).

This is due to the fact that when parsing functions, procedures and triggers, the sql-parser includes everything in the body of the statements.

With the current fix, this is not the case anymore. This has an impact on existing data test sets which seemed not to be valid.

@codecov
Copy link

codecov bot commented Apr 3, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (d576334) 97.04% compared to head (599c597) 97.04%.

Additional details and impacted files
@@            Coverage Diff            @@
##              5.8.x     #438   +/-   ##
=========================================
  Coverage     97.04%   97.04%           
- Complexity     2216     2218    +2     
=========================================
  Files            69       69           
  Lines          5103     5107    +4     
=========================================
+ Hits           4952     4956    +4     
  Misses          151      151           
Impacted Files Coverage Δ
src/Statements/CreateStatement.php 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@niconoe-
Copy link
Contributor

@williamdes Code coverage is yelling but at unchanged files, like it did a few weeks ago with some PR of mine. I think therefore we shouldn't consider those "failures" and this PR is OK and could be merged, wdyt?

Thanks 🙂

@williamdes
Copy link
Member

williamdes commented Apr 11, 2023

@williamdes Code coverage is yelling but at unchanged files, like it did a few weeks ago with some PR of mine. I think therefore we shouldn't consider those "failures" and this PR is OK and could be merged, wdyt?

Thanks 🙂

Hi
Sorry for not replying earlier
I reviewed the contents and was concerned that the DELIMITER would maybe mess up with how we use the parser to read procedures at phpMyAdmin
So I need to test that or someone could test?
Bu it's okay for me, I think I can merge this in the following days
And maybe release the version?
We could do a 5.8.0-rc1 maybe
So we could push more stuff to 5.8 before the next phpMyAdmin release?

PS: that's okay for codecov

@Tithugues
Copy link
Contributor Author

Tithugues commented Apr 11, 2023

@williamdes Code coverage is yelling but at unchanged files, like it did a few weeks ago with some PR of mine. I think therefore we shouldn't consider those "failures" and this PR is OK and could be merged, wdyt?
Thanks slightly_smiling_face

Hi Sorry for not replying earlier I reviewed the contents and was concerned that the DELIMITER would maybe mess up with how we use the parser to read procedures at phpMyAdmin So I need to test that or someone could test? Bu it's okay for me, I think I can merge this in the following days And maybe release the version? We could do a 5.8.0-rc1 maybe So we could push more stuff to 5.8 before the next phpMyAdmin release?

PS: that's okay for codecov

Hi,

Thanks for the answer.

I think I can provide an pretty clear example about what's happening with triggers, procedures and functions.
Let's go with the file tests/data/parser/parsephpMyAdminExport1.in. As you can see, there are many statements. I'd like to focus on the first trigger…
Add the next 2 lines at the very end of the \PhpMyAdmin\SqlParser\Parser::parse function:

        $body = $this->statements[2]->statements[6]->body;
        die(var_dump(implode(' ', array_column($body, 'token'))));

Now, let's parse the .in file, using the bin/lint-query.
Here is the result:

INSERT   INTO   monitoring__times_mirror 
 ( `idServer` ,   `time` ,   `totalTime` )   VALUES ( new . idServer ,   new . time ,   new . totalTime ) 
 $$ 
 DELIMITER   ; 
 DELIMITER   $$ 
 CREATE   TRIGGER   `deleteTimes`   AFTER   DELETE   ON   `monitoring__times`   FOR EACH ROW   DELETE   FROM   monitoring__times_mirror 
 WHERE   `idServer` = old . idServer 
 AND   `time` = old . time 
 AND   `totalTime` = old . totalTime 
 $$ 
 DELIMITER   ; 
 DELIMITER   $$ 
 CREATE   TRIGGER   `updateTimes`   AFTER   UPDATE   ON   `monitoring__times`   FOR EACH ROW   UPDATE   monitoring__times_mirror 
 SET   `idServer` = new . idServer , 
 `time` = new . time , 
 `totalTime` = new . totalTime 
 WHERE   `idServer` = old . idServer 
 AND   `time` = old . time 
 AND   `totalTime` = old . totalTime 
 $$ 
 DELIMITER   ; 

 --
 
 -- Index pour les tables déchargées 
 --
 

 --
 
 -- Index pour la table `monitoring__times` 
 --
 
 ALTER   TABLE   `monitoring__times` 
   ADD   UNIQUE KEY   `idServer`   ( `idServer` , `time` )   USING   BTREE   COMMENT   'Unique idServer/time' , 
   ADD   KEY   `INDEX_totalTime`   ( `totalTime` )   USING   BTREE   COMMENT   'Index for totalTime column' ; 

 --
 
 -- Contraintes pour les tables déchargées 
 --
 

 --
 
 -- Contraintes pour la table `monitoring__times` 
 --
 
 ALTER   TABLE   `monitoring__times` 
   ADD   CONSTRAINT   `monitoring__times__idServer`   FOREIGN KEY   ( `idServer` )   REFERENCES   `monitoring__servers`   ( `id` ) ; 
 COMMIT ; 

 /*!40101   SET   CHARACTER_SET_CLIENT = @OLD_CHARACTER_SET_CLIENT   */ ; 
 /*!40101   SET   CHARACTER_SET_RESULTS = @OLD_CHARACTER_SET_RESULTS   */ ; 
 /*!40101   SET   COLLATION_CONNECTION = @OLD_COLLATION_CONNECTION   */ ; 

As you can see, everything after the beginning of the trigger (next statements, comments, …) are considered as being part of the first trigger…

Let's do the exact same test but on the fix branch now. The result is:

INSERT   INTO   monitoring__times_mirror 
 ( `idServer` ,   `time` ,   `totalTime` )   VALUES ( new . idServer ,   new . time ,   new . totalTime )

Please let me know if you need any additional information.

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.

Thank you for all your contributions @Tithugues !

@williamdes williamdes self-assigned this Apr 14, 2023
@williamdes williamdes added this to the 5.8.0 milestone Apr 14, 2023
williamdes added a commit that referenced this pull request Apr 14, 2023
Pull-request: #438

Signed-off-by: William Desportes <williamdes@wdes.fr>
@williamdes williamdes merged commit 9ff553f into phpmyadmin:5.8.x Apr 14, 2023
MauricioFauth added a commit to phpmyadmin/phpmyadmin that referenced this pull request Apr 19, 2023
Related to phpmyadmin/sql-parser#438

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
@williamdes
Copy link
Member

williamdes commented Apr 22, 2023

I reviewed the contents and was concerned that the DELIMITER would maybe mess up with how we use the parser to read procedures at phpMyAdmin

Oh yeah I was right, phpMyAdmin needs fixing after this PR

If you view a complex procedure that has a ; the procedure ends at the end of the line
In edit procedures/functions view.

The fixes:
phpmyadmin/phpmyadmin@a88c9a3
and
phpmyadmin/phpmyadmin@99881de
Using test data: a3a699d

williamdes added a commit to phpmyadmin/phpmyadmin that referenced this pull request Apr 22, 2023
Related to 5a2baf6
Related to phpmyadmin/sql-parser#438

Signed-off-by: William Desportes <williamdes@wdes.fr>
williamdes added a commit to phpmyadmin/phpmyadmin that referenced this pull request Apr 22, 2023
Related to 5a2baf6
Related to phpmyadmin/sql-parser#438

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.

3 participants