May 2018
Intermediate to advanced
576 pages
30h 25m
English
Rewrite your application so that the SQL is transformed into two separate transactions, with a double-check to ensure that the rows haven't changed (pay attention to the placeholders):
SELECT A.*, (A.*::text) AS old_acc_infoFROM accounts a WHERE holder_name ='BOB';<do some calculations here>UPDATE accounts SET balance = 42.00WHERE holder_name ='BOB'AND (A.*::text) = <old_acc_info from select above>;
Then, check whether the UPDATE operation really did update one row in your application code. If it did not, then the account for BOB was modified between SELECT and UPDATE, and you probably need to rerun your entire operation (both transactions).