MYSQL: Select Then Update. Double Processing Issue
-
03-07-2021 - |
Question
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)
OTHER TIPS
I think you need to clarify what you mean by "Google sends 2 responses at the same time".
I'm assuming you are referring to Google Checkout API - and if so, each notification Google sends represents "something". You have to identify what the Notification
is - in other words, you maybe "fixing" an issue that doesn't exist and are doing so based on your perception of what Google sends (rather than noticing that they, each Notification
, are distinct).
Hth....