Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql linter for mysql and php

I'm building an application that generates a lot of sql queries. Some of them are complex (to me) and writing good tests is tricky.

As a sanity test it would be nice to run the generated SQL queries through a linter. So, the tests wouldn't actually run/execute the queries on the database, but it would parse the query and make sure it looks valid.

I realize this isn't a great test, but I figure it would be fast, and my PHP linter has helped me catch a lot of issues, so if I could build this into unit tests it seems like a fast way to catch some low hanging fruit.

I'm working in PHP and MySql (on linux) so I'd prefer a solution for that environment but I'll take what I can get. Maybe it will point me in the right direction.

like image 736
Jachin Avatar asked Oct 22 '22 03:10

Jachin


1 Answers

Several possibilities (I confess - the only one I'm personally familiar with is SQL Fiddle):

  • SQL Fiddle: http://sqlfiddle.com/

  • MySql Test Framework:

http://dev.mysql.com/doc/mysqltest/2.0/

  • Google Test Framework:

http://dev.mysql.com/doc/mysqltest/2.0/en/unit-tests-google-test.html

  • myTAP:

https://github.com/hepabolu/mytap

Since you're using PHP, you should probably also look at PHPUnit:

  • http://phpunit.de/manual/3.7/en/database.html

'Hope that helps ... at least a little

like image 125
paulsm4 Avatar answered Oct 27 '22 10:10

paulsm4