By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,349 Members | 1,353 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,349 IT Pros & Developers. It's quick & easy.

mysql_errorno() and a more complete error description

P: n/a
Jes
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

Oct 7 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Jes wrote:
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
Oct 7 '08 #2

P: n/a
Jes wrote:
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 Ivn 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.
js*******@attglobal.net
==================

Oct 7 '08 #3

P: n/a
Jes
On Oct 7, 10:22*pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Jes wrote:
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 Ivn 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
Oct 7 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.