I'm making a simple tool that will get a string of MySQL commands and run it (on several DB servers sequentially). I trust the users to be sensible, but mistakes happen, and I'm looking for a way to prevent basic typos:
Is there a way to validate, at runtime, (relatively simple) MySQL queries to see if they're syntactically correct?
I'm not looking for semantic correctness, e.g. table names or join applicability; just something like a spellcheck for SQL queries.
In other words,
SELECT * FROM x;
or
INSERT INTO x SET id=1,bar="foo";
would be marked valid, whereas any of those would not:
SELECT FROM x;
SECLET * RFOM x;
ISNETR INTO x SET id=1;
HJBGYGCRYTCY;
For SELECTs, I could bend EXPLAIN to my needs - run EXPLAIN SELECT (...) and watch for errors, but is there a way to check for other commands as well?