mysqlgoogle-checkout

MYSQL: Select Then Update. Double Processing Issue


The Issue:

I am building a google checkout callback interface. The issue I am having is that google sends 2 responses at the same time back to the site and the site processes both of them, so I end up with 2 updates. The code is written to check if the entry exists, and if it does not insert or update as needed.

The time stamps will be identical and it will post 2 transactions. I had the database at Innodb, but I changed it to MyISAM in hopes that it would resolve the issue.

Question:

Is it possible to have an SQL query select and then update on a conditional. Or is there something else I can do to get around this issue?


Solution

  • You can use EXIST to perform your update only of your select return a result

     UPDATE TABLE1 SET col=`value` 
     where exists (select 1 from TABLE2 where condition)