On Tue, Sep 30, 2003 at 09:39:03PM +0100, Andy Hassall wrote:
> Tim Bunce wrote:
>
> Being able to write something like:
>
> $sth_insert->execute(1,2,3);
> if ($dbh->err) {
> if ($dbh->dbi_error_code == DBI::ERROR_PRIMARY_KEY_VIOLATION) {
> // do an update instead
> }
> if ($dbh->dbi_error_code ==
> DBI::ERROR_FOREIGN_KEY_VIOLATION_PARENT_NOT_FOUND) {
> // add necessary parent records, retry insert
> }
> }
>
> ... and not worry about which DBD it's using could be useful, certainly
> neat anyway (I can never remember the numeric codes to check for when
> switching between Oracle and MySQL).
>
> What would need mapping? An initial list could be:
>
> Primary key violation
> Unique key violation
> Not null constraint violation
> Check constraint violation
> Foreign key violation - parent not found on insert
> Foreign key violation - child records exist on update or delete
All very wonderful in theory. But what about databases and drivers
that can't provide that level of detail?
Tim.