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

Fixing parser errors when adding columns with SET type #344

Merged
merged 2 commits into from Aug 16, 2021

Conversation

iifawzi
Copy link
Contributor

@iifawzi iifawzi commented Aug 15, 2021

Hi, This PR should fix #168 and the issues shown #337

I will clarify the changes in a review.

Testing in PMA too.

@codecov
Copy link

codecov bot commented Aug 15, 2021

Codecov Report

Merging #344 (88d7f3e) into QA (09fefbf) will decrease coverage by 0.02%.
The diff coverage is 90.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##                 QA     #344      +/-   ##
============================================
- Coverage     99.80%   99.78%   -0.03%     
- Complexity     1911     1914       +3     
============================================
  Files            63       63              
  Lines          4596     4605       +9     
============================================
+ Hits           4587     4595       +8     
- Misses            9       10       +1     
Impacted Files Coverage Δ
src/Components/AlterOperation.php 98.97% <90.00%> (-1.03%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 09fefbf...88d7f3e. Read the comment docs.

Copy link
Contributor Author

@iifawzi iifawzi left a comment

Choose a reason for hiding this comment

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

That's what I've noticed, I've also added some comments in the code, to make things clearer in the future

src/Components/AlterOperation.php Outdated Show resolved Hide resolved
src/Components/AlterOperation.php Outdated Show resolved Hide resolved
@williamdes williamdes added this to the 4.7.3 milestone Aug 15, 2021
@williamdes williamdes self-assigned this Aug 15, 2021
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.

💯 Oh yeah, this looks neat and readable
Codecov seems to complain about a non covered line for some reason

@williamdes
Copy link
Member

While trying to create some particular query I found this one made by phpMyAdmin on table charset change

ALTER TABLE `d` DEFAULT CHARSET=hp8 COLLATE hp8_english_ci;

Errors:

#1: Missing comma before start of a new alter operation. (near "DEFAULT CHARSET" at position 16)
#2: Unrecognized alter operation. (near "DEFAULT CHARSET" at position 16)

Keeping this to add a new test before merging

And another bunch of them

$ ./bin/lint-query --query 'ALTER TABLE `d` CHARSET=hp8'
#1: Unrecognized alter operation. (near "" at position 0)
$ ./bin/lint-query --query 'ALTER TABLE `d` CHARSET=hp8;'
#1: Unrecognized alter operation. (near ";" at position 27)
$ ./bin/lint-query --query 'ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;'
$ ./bin/lint-query --query 'ALTER TABLE `d` CHARACTER SET utf8;'
#1: Unrecognized alter operation. (near ";" at position 34)
$ ./bin/lint-query --query 'ALTER TABLE `d` CHARACTER SET utf8 COLLATE utf8_general_ci;'
#1: Unrecognized alter operation. (near ";" at position 58)

Would you mind if I add them into QA and then you rebase/squash ontop of it ?

@iifawzi
Copy link
Contributor Author

iifawzi commented Aug 15, 2021

Interesting, gonna figure out how.

Would you mind if I add them into QA and then you rebase/squash ontop of it ?

Sure, feel free to add them.

@williamdes
Copy link
Member

Interesting, gonna figure out how.

Would you mind if I add them into QA and then you rebase/squash ontop of it ?

Sure, feel free to add them.

Done as 09fefbf

@iifawzi
Copy link
Contributor Author

iifawzi commented Aug 15, 2021

It seems like all new added tests aren't related to the changes we introduced in this PR.
They are all caused because of

if ($ret->options->isEmpty()) {
$parser->error('Unrecognized alter operation.', $list->tokens[$list->idx]);
}

looks like the fix should be somewhere in the OptionsArray::parse method because it return empty array. I will try to investigate more :')

$ret->options = OptionsArray::parse($parser, $list, $options);

Also, if i'm not mistaken, parseAlterTableCharacterSet4.in is passing with no errors - after this fix -

Signed-off-by: Fawzi E. Abdulfattah <iifawzie@gmail.com>
Signed-off-by: Fawzi E. Abdulfattah <iifawzie@gmail.com>
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.

🚢

@williamdes williamdes merged commit 5f0d27e into phpmyadmin:QA Aug 16, 2021
@williamdes
Copy link
Member

williamdes commented Aug 16, 2021

phpstan complains about this possible null value, added a check in 6ad0bb6

 ------ ------------------------------------------------------------------- 
  Line   src/Components/AlterOperation.php                                  
 ------ ------------------------------------------------------------------- 
  302    Cannot access property $value on PhpMyAdmin\SqlParser\Token|null.  
  305    Cannot access property $value on PhpMyAdmin\SqlParser\Token|null.  
 ------ ------------------------------------------------------------------- 

williamdes added a commit that referenced this pull request Aug 16, 2021
Pull-request: #344

Signed-off-by: William Desportes <williamdes@wdes.fr>
@williamdes
Copy link
Member

williamdes commented Aug 16, 2021

All tools pass but phpcs is nuts (only on master branch): https://github.com/phpmyadmin/sql-parser/runs/3344576860#step:7:10

Fixed, it was ridiculous: cf9cb91

williamdes added a commit that referenced this pull request Aug 16, 2021
Pull-request: #344

Signed-off-by: William Desportes <williamdes@wdes.fr>
@williamdes
Copy link
Member

williamdes commented Aug 16, 2021

All good, but unable to have the last line covered if ($token->value === 'CHARACTER SET') { searching

Fixed in fd1552e 🎉

williamdes added a commit that referenced this pull request Aug 16, 2021
Pull-request: #344

Signed-off-by: William Desportes <williamdes@wdes.fr>
@iifawzi
Copy link
Contributor Author

iifawzi commented Aug 16, 2021

Happy to see everything fixed! 🥳🥳❤️

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

2 participants