I am working on my demo project - its simple bank.
I have one problem.
I need to add some virtual money into my account.
But I need to do it "like atomic operation", I need to query some data before update.
Like:
Query table A // select from table A
Query table B // select from table B
if (A + B > X)
Add money // insert into table C
Problem is, that during the query A or B another thread can start some work.
Which technique of mysql should I use?
Example: Happy example
User see A = 1, B = 1 in dashboard
User will send request
SELECT A
SELECT B
INSERT A + B // result is 2
Sad example
User see A = 1, B = 1 in dashboard
User will send request
SELECT A
// SOMEONE CHANGED B RIGHT NOW TO 10 !
SELECT B
INSERT A + B // result is 12