sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Jes's Avatar

mysql_errorno() and a more complete error description


Question posted by: Jes (Guest) on October 7th, 2008 08:55 PM
Hi

Is there any way to construct a more meaningful error description so
that it can be displayed to the user

Eg. Table Country - Fields Country Code and Country Name - Both
fields are unique and code is the primary key.

I would like to display something like 'Country code already exists'.

Current display will be 'Duplicate entry 'AA' for key 1'

Is it possible to change key 1 with the name of the field generating
the error ?

Thanks

3 Answers Posted
=?UTF-8?B?SXbDoW4gU8OhbmNoZXogT3J0ZWdh?='s Avatar
=?UTF-8?B?SXbDoW4gU8OhbmNoZXogT3J0ZWdh?= October 7th, 2008 09:15 PM
Guest - n/a Posts
#2: Re: mysql_errorno() and a more complete error description

Jes wrote:
Quote:
Originally Posted by
Current display will be 'Duplicate entry 'AA' for key 1'
>
Is it possible to change key 1 with the name of the field generating
the error ?


Do proper error checking before running the SQL query.


Cheers,
--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

This tagline is SHAREWARE! To register, send me $10
Jerry Stuckle's Avatar
Guest - n/a Posts
#3: Re: mysql_errorno() and a more complete error description

Jes wrote:
Quote:
Originally Posted by
Hi
>
Is there any way to construct a more meaningful error description so
that it can be displayed to the user
>
Eg. Table Country - Fields Country Code and Country Name - Both
fields are unique and code is the primary key.
>
I would like to display something like 'Country code already exists'.
>
Current display will be 'Duplicate entry 'AA' for key 1'
>
Is it possible to change key 1 with the name of the field generating
the error ?
>
Thanks
>
>


No, MySQL won't do that for you. If you want something like this, you
can either check for duplicates before the insert like Iván suggested,
or parse the error message yourself.

Checking for duplicates before doing an INSERT is OK, but ensure you
LOCK TABLE so someone else doesn't get in between your SELECT and your
INSERT (uncommon, but it does happen!).

Alternatively, after you get the duplicate key back, do a SELECT for a
match of Country Code OR Country Name and check the row(s) which come
back to see which is a duplicate.

Alternatively, keep track of which index refers to which column and test
in your code. I like this least of all :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
Join Bytes!
==================

Jes's Avatar
Guest - n/a Posts
#4: Re: mysql_errorno() and a more complete error description

On Oct 7, 10:22*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Quote:
Originally Posted by
Jes wrote:
Quote:
Originally Posted by
Hi

>
Quote:
Originally Posted by
Is there any way to construct a more meaningful error description so
that it can be displayed to the user

>
Quote:
Originally Posted by
Eg. Table Country - *Fields Country Code and Country Name - Both
fields are unique and code is the primary key.

>
Quote:
Originally Posted by
I would like to display something like 'Country code already exists'.

>
Quote:
Originally Posted by
Current display will be 'Duplicate entry 'AA' for key 1'

>
Quote:
Originally Posted by
Is it possible to change key 1 with the name of the field generating
the error ?

>
Quote:
Originally Posted by
Thanks

>
No, MySQL won't do that for you. *If you want something like this, you
can either check for duplicates before the insert like Iván suggested,
or parse the error message yourself.
>
Checking for duplicates before doing an INSERT is OK, but ensure you
LOCK TABLE so someone else doesn't get in between your SELECT and your
INSERT (uncommon, but it does happen!).
>
Alternatively, after you get the duplicate key back, do a SELECT for a
match of Country Code OR Country Name and check the row(s) which come
back to see which is a duplicate.
>
Alternatively, keep track of which index refers to which column and test
in your code. *I like this least of all :-)
>
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -
>
- Show quoted text -


Thanks to all
 
Not the answer you were looking for? Post your question . . .
197,022 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,022 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors