How can I check (My)SQL statements for syntactical correctness

Viewed 16629

we're currently setting up out integration server and during that process we've set up pre-commit hooks on the SVN so that our developers can't check in files that are syntactically invalid (primarily PHP and XML).

We also have a bunch of .sql files (for MySQL) which I'd like to lint as well. Unfortunately, Google didn't turn up anything useful for this task.

Any ideas?

5 Answers

Disclaimer: I have not yet tried out any of these tools! YMMV!

PHPMyAdmin's validating SQL parser is an actively developed open source project and would be my best bet right now in 2021.

The other more or less current project I've found doesn't look as mature, but here it is:

Persist SQL Query "The best and most complete query builder/parser for MySQL (PHP)" according to its Github Tagline, but it's not explicitly validating, but it from the source you can see it does throw Exceptions if a query can't be parsed properly.

Just to mention it: PHP-SQL-Parser is non-validating, so it does not qualify for linting.

Related