Re: [CDBI] processing mysql errors
[prev]
[thread]
[next]
[Date index for 2005/09/05]
> 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