Coldfusion duplication issues! How should I deploy my inserts to avoid this?
Posted on 2013-12-09
Hi all -
My current script runs something like this:
- Cfquery ---> check to see if serialized form is defined (I have a unique ID I'm passing in the form, check to see if that unique ID is defined in the database).
- CFIF recordcount of query is greater than 0
- Cfquery ----> Insert
- Cfquery ----> Update
What I'm GUESSING is happening is that when the double click happens, the queries to check are happening simultaneously, and by the time the first click inserts, the second click has already checked and found zero recordcount, thus inserting a duplicate.
I've tried to do some digging on how to solve this, I'm clueless. Someone said stored procedure, someone said use IF NOT EXISTS in the SQL (but I, believe it or not, managed to generate a duplicate with this method somehow as well).
Time to ask the experts...what is the BEST way to avoid duplicate inserts when working with ColdFusion? How should I resolve?