in reply to How should I handle $sth->execute() errors?

Your concern for error-handling is meritorious, but it's very common to DROP tables in db build scripts before CREATE'ing them. I don't know if that would work for SQLite, though.

Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
  • Comment on Re: How should I handle $sth->execute() errors?

Replies are listed 'Best First'.
2Re: How should I handle $sth->execute() errors?
by jeffa (Bishop) on Dec 04, 2003 at 00:05 UTC

    You can do this in SQLite ... but regardless of which DBD you use*, this technique will fail if the table is already gone when you issue the DROP command. It works like a charm if you add the drop statement after your code yacks the first time you try to ADD a table that already exists -- but as soon as something else DROP's the table, your script breaks "in the opposite direction," so to speak. I think mifflin's suggestion of "catching an exception" by trapping inside eval is a more robust solution.

    * unless you are using something like MySQL that offers CREATE TABLE foo IF NOT EXISTS ...

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    

      You'll get no arguments from me concerning error-handling. I just had a sense that the poster was not familiar with the DROP/CREATE idiom in datababase build scripts. :)

      Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"