Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

How to trap duplicate entries errors.

Quote Reply
How to trap duplicate entries errors.
I want to prevent creation of duplicate categories so I used UNIQUE for the Name field.

What I did works fine, the problem is: how can I trap the error sql gives and return it in a nice format?

It happens also if i try to add an existing username (Users table).


Thank you in advance



lepo

Quote Reply
Re: How to trap duplicate entries errors. In reply to
Once you use something like 'unique' you are at the last step. You should try to trap the error BEFORE it's generated, then handle the error if it's ever actually generated.

So, take a look at jump.cgi ...

If the record exists, do one thing, if it doesn't, do another.

The logic should be pretty close to how Hit_Track is updated or inserted.




Quote Reply
Re: How to trap duplicate entries errors. In reply to
Hello!

Look at the DBSQL.pm and edit the error generating routine.

there the error handling routines are defined, I beleive. Nowhere else I can remember. Although, my knowledge about the scripts is half a year old.

[This message has been edited by rajani (edited May 02, 2000).]
Quote Reply
Re: How to trap duplicate entries errors. In reply to
Not that simple! I finally figured the solution. I wanted to prepare a very general function to allow me to prevent this kind of error in all sinsertions.

So... I added a new filed in db_def: $unique. When this switch is = 1 means that I want only one in the table.
Then I added a very simple count query in the verify DBSQL internal routine to check avery field that has $db_def{unique} activated.

Little tricky but I just followed the way Alex did the rest.