List:General Discussion« Previous MessageNext Message »
From:Thimble Smith Date:August 6 1999 11:40pm
Subject:Re: matching & adding in one script
View as plain text  
At 16:25, 19990806, Lee Chor Kee wrote:
>i have a html form and want to pass the value (example:email) into my database
>But before i pass/enter ,i want to check/verify whether it already exist or
>not in my database before adding 
>it to my database.
>The problem is how do i going to include them into one perl script without
>separate it into
>2 difference step. In other word ,matching and adding process are done in one
>Is there possible to join them together in one script ??does anybody can give
>me an advice or example??

Kee, if the value you are inserting is for a UNIQUE column (the PRIMARY
KEY column, or a column with a UNIQUE index), then you can try to do
the INSERT, and if it fails with the error ER_DUP_ENTRY (1062), you
know that it was already in the table.

If it is not a UNIQUE column, then you should first LOCK TABLES ... WRITE,
so that no one else will insert the row while you are not looking.  Then
you should try to find a matching row, using SELECT.  If no rows match
the value you want to insert, then you can safely issue the INSERT query.
Once you're done, UNLOCK TABLES to allow others access.

If this does not answer your question, please reply with some examples
of what you want to do.

matching & adding in one scriptLee Chor Kee7 Aug
  • Re: matching & adding in one scriptThimble Smith7 Aug