in reply to DBI - validate SQL without executing

What about creating a statement handle on the statement using prepare? Couldn't you check DBI::errstr on a prepare to determine if the statement was valid?

Maybe something like this simple example ...

#!/usr/local/bin/perl use warnings; use strict; use DBI; require '/up/web/standard.pl'; my $dbh = db_connect_local(); # my home-grown connection routine my $statement = 'select blah from my_table'; # blah is not a valid col +umn on that table. my $sth = $dbh->prepare($statement); unless ($sth) { print "Error: $DBI::errstr\n"; }

Update: It seems this does not work for MySQL, but it does work under DBD::Oracle. Thanks to erix and tye for pointing that out.


No good deed goes unpunished. -- (attributed to) Oscar Wilde