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

Use proper sql parser #123

Open
7 of 13 tasks
staabm opened this issue Jan 17, 2022 · 5 comments
Open
7 of 13 tasks

Use proper sql parser #123

staabm opened this issue Jan 17, 2022 · 5 comments
Labels
enhancement New feature or request
Milestone

Comments

@staabm
Copy link
Owner

staabm commented Jan 17, 2022

Related problems

https://github.com/phpmyadmin/sql-parser

https://github.com/greenlion/PHP-SQL-Parser

@craigfrancis
Copy link
Contributor

Might be worth looking at the PDO function that parses parameters, to see how it works.

It seems to use pdo_parse_params(), which is a bit more complicated than using the BINDCHR regex by itself (used later as PDO_PARSER_BIND).

It supports escaped question marks (??), comments (/* What about X? */ or -- To fix?), and quoted string values (see ANYNOEOF?).

@staabm
Copy link
Owner Author

staabm commented Jan 17, 2022

Would be great if you could provide failling testcases if you have special cases in mind

@craigfrancis
Copy link
Contributor

I don't have any real examples, but how about?

  • SELECT * FROM cmsdomain WHERE url LIKE "%?%";
  • SELECT * FROM cmsdomain WHERE url LIKE "%:tag_name%";
  • SELECT * FROM cmsdomain WHERE cmsdomainid IN (1,2) /* What about 3? */
  • SELECT * FROM cmsdomain WHERE 1=2; -- :TODO?

@staabm
Copy link
Owner Author

staabm commented Jan 19, 2022

I don't have any real examples, but how about?

* `SELECT * FROM cmsdomain WHERE url LIKE "%?%";`

* `SELECT * FROM cmsdomain WHERE url LIKE "%:tag_name%";`

* `SELECT * FROM cmsdomain WHERE cmsdomainid IN (1,2) /* What about 3? */`

* `SELECT * FROM cmsdomain WHERE 1=2; -- :TODO?`

these basic examples are now covered by #145

still on the long run we might better use a sql parser. lets see whether people report problems with their queries when running phpstan-dba on real projects

@staabm staabm added the enhancement New feature or request label Jan 30, 2022
@staabm
Copy link
Owner Author

staabm commented Aug 26, 2022

on twitter the SQLFTW/sqlftw project was suggested as a proper parser

@staabm staabm added this to the SQL AST milestone Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants