in reply to Re^3: Best Perlish way to test if a mysql table exists?
in thread Best Perlish way to test if a mysql table exists?

re-write trappig code for every line of sql in the script....
Not necessary, you can set RaiseError for just that particular query. BTW, did you know you can localize hash/array values? Even if the hash/array is a lexical variable?
eval { local $DBH->{RaiseError} = 1; local $DBH->{PrintError} = 0; $sth = $DBH->prepare($sql); $sth->execute; 1; }; # table was found if $@ is empty
Alternately, you can just set RaiseError/PrintError on the individual statement handle (not the database connection handle).

blokhead

Replies are listed 'Best First'.
Re^5: Best Perlish way to test if a mysql table exists?
by Aristotle (Chancellor) on Jan 31, 2005 at 06:24 UTC

    Except it wasn't the point to set that for a single query. It's usually best to set RaiseError on the connection handle and wrap larger blocks of calls with an eval; that frees you from the responsibility of constantly checking $dbh->err. If you aren't already using RaiseError, I don't see how going through all the trouble to enable it for one query is better than the regular $dbh->err check.

    Makeshifts last the longest.