Re: [CDBI] processing mysql errors

[prev] [thread] [next] [Date index for 2005/09/05]

From: Brad Bowman
Subject: Re: [CDBI] processing mysql errors
Date: 04:42 on 05 Sep 2005

> Thanks for this. Yes DBD::mysql makes some attributes available, 
> including mysql_errno and mysql_error. I believe these are propagated up 
> through DBI and Class::DBI. But the detailed information, which users 
> want and which my attempt at automatic recovery needs, is buried in the 
> MySQL mysql_error string, AFAIK. So it seems like I need to parse that 
> and I can't believe I'm the first to want to do it :)

You're not the first.  Although it shames me to admit it, I'm rewriting
the "Duplicate entry" key violation errors.  I couldn't find a module to
do this, nor much guidance in the MySQL docs.  The code therefore
depends on the formatting and other, possibly unstable, properties of
the error message.

It has worked ok for my modest needs but it's inherently flaky.
For instance, to rewrite a message like:
   "Duplicate entry '123' for key 2"

You need to know what key 2 is and the only documentation I could find
is in the CREATE TABLE docs:

   In the created table, a PRIMARY KEY is placed first, followed by all
   UNIQUE indexes, and then the non-unique indexes. This helps the MySQL
   optimizer to prioritize which index to use and also more quickly to
   detect duplicated UNIQUE keys.

So I'm dependent on something which happens to suit the optimizer.
Furthmore, the '123' data string has dashes inserted between the items
for multi-column data.  I vaguely recollect dashes in the data being
unescaped, so you may hit some ambiguity.

See also:
   DESCRIBE $table
   SHOW INDEX FROM $table

Have I scared you off this approach yet?

Brad




_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] processing mysql errors
Dave Howorth 11:02 on 25 Aug 2005

Re: [CDBI] processing mysql errors
Matt S Trout 11:21 on 25 Aug 2005

Re: [CDBI] processing mysql errors
David Baird 11:37 on 25 Aug 2005

Re: [CDBI] processing mysql errors
Dave Howorth 11:49 on 25 Aug 2005

Re: [CDBI] processing mysql errors
Matt S Trout 13:01 on 25 Aug 2005

Re: [CDBI] processing mysql errors
Brad Bowman 04:42 on 05 Sep 2005

Re: [CDBI] processing mysql errors
Dave Howorth 09:37 on 06 Sep 2005

Generated at 16:14 on 20 Sep 2005 by mariachi v0.52