Can there be any proper error handling be implemented into a SQL UNIQUE Constraint? So far i'm obviously getting: Error: Duplicate entry 'test1' for key 'username'
But i'd like to have it display a custom comment if possible
Can there be any proper error handling be implemented into a SQL UNIQUE Constraint? So far i'm obviously getting: Error: Duplicate entry 'test1' for key 'username'
But i'd like to have it display a custom comment if possible
You should check in your app code before inserting this
row that no other row exists with the same username.
Then if it exists, show the error you want to the user.
Parsing this unique constraint error
(after you get it) is not a good idea.
So do it before, not after.
select) and the actual insert. So you have to check for any error during insert anyway and in the end you wind up with the error checking and the double load on the server - which makes the application non-scalable.