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

Just read up on RaiseError - maybe a possibility. But that would create an error trapping nightmare for me having to re-write trappig code for every line of sql in the script....

Oh, for a "if table exists" function!

Forget that fear of gravity,
Get a little savagery in your life.

  • Comment on Re^3: Best Perlish way to test if a mysql table exists?

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

    To be honest, I don't think such functionality is particularly warranted. Constantly checking for the existence of a table smacks of bad design. Sometimes we are stuck with bad design, of course.

    Makeshifts last the longest.

Re^4: Best Perlish way to test if a mysql table exists?
by blokhead (Monsignor) on Jan 31, 2005 at 05:35 UTC
    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

      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.