in reply to DBI - validate SQL without executing

If there's any way to use your RDBMS directly (e.g. the other suggestions to prepare but not execute or to add a WHERE 1=0), that would be your best bet. If that won't work, SQL::Statement can be tweaked to do some DBMS-specific work. It won't handle things like CASE statements and subqueries (other than those it supports already) since those invovle a different level of parsing.

But you can teach it about DBMS specific data types, functions, and operators with the CREATE and DROP commands for types, functions and operators. For example if your DBMS doesn't support BLOB as a data type, issuing $dbh->do("DROP TYPE blob") before you begin will cause it to reject the word BLOB when used as a data type. "CREATE TYPE foo" will do the reverse - accept "foo" as a data type. The same works with functions and some operators (e.g. SLIKE or RLIKE).

The other thing you can do is use S::S as a first pass validator - in other words, you could use it to filter out all of the statements it recognizes as valid and then the ones that are left over you'd need to deal with some other way.

Let me know if you need more specifc tips.
  • Comment on Re: DBI - validate SQL without executing