Let me rephrase. I insert a row and recieve a 1062 error (Key violation).
How do I determine, at run-time, which of the 3 possible columns has the
error. I guess I could parse the mysql_error message string. But, that
seems likely to change in the future. Or, I can test each column for
uniqueness via individual selects before I issue the insert.
Thanks
>From: Jeremy Zawodny <Jeremy@stripped>
>Reply-To: mysql@stripped
>To: Scot Campbell <scotcampbell@stripped>
>CC: mysql@stripped
>Subject: Re: Unique Key Violation - How to determine which key
>Date: Tue, 16 Sep 2003 20:31:21 -0700
>
>On Tue, Sep 16, 2003 at 08:25:39PM -0700, Scot Campbell wrote:
> > I have a table w/ a primary key and 2 additional unique keys.
> >
> > How can I determine which key was in error when a key violation occurs
> > (error=1062)?
> >
> > The call is issued from PHP (4.4.3).
> >
> > I can retrieve a message w/ mysql_error() which returns "Duplicate entry
> > 'email@removed' for key 3"
> >
> > I'd rather get the name of the unique key, in this case I named it
> > `IDX_EMAILADDR`.
> >
> > Any ideas? Thanks
>
>Look at SHOW KEYS or SHOW CREATE TABLE and find the 3rd key.
>
>Jeremy
>--
>Jeremy D. Zawodny | Perl, Web, MySQL, Linux Magazine, Yahoo!
><Jeremy@stripped> | http://jeremy.zawodny.com/
>
>MySQL 4.0.15-Yahoo-SMP: up 3 days, processed 102,697,946 queries (378/sec.
>avg)
_________________________________________________________________
Get 10MB of e-mail storage! Sign up for Hotmail Extra Storage.
http://join.msn.com/?PAGE=features/es