Data consistency in multiple updates

When AutoCommit = false and multiple Update() calls are executed within the same transaction, error handling differs significantly:

  • Traditional C/S (partial success) -- If one update fails, only the failed operation is rolled back. Preceding updates are committed successfully within the transaction.

  • PowerServer (atomic rollback) -- If an update fails, preceding successful updates in the same transaction may also be rolled back to maintain data consistency.

  • Best practice -- Developers should check the execution result of each update operation and decide whether to commit or rollback to ensure consistent behavior across both C/S and cloud environments.

    In the following example, three DataWindow objects (dw_1, dw_2, and dw_3) execute Update() operations within the same transaction.

    Traditional C/S: If the update of dw_2 fails, only that operation is rolled back. The updates of dw_1 and dw_3 are committed successfully.

    PowerServer: If the update of dw_2 fails, both the failed operation and any preceding successful updates within the same transaction (such as dw_1) are rolled back. Subsequent operations (such as dw_3) are executed in a new transaction and may be committed independently.

    SQLCA.Autocommit = false;
    
    dw_1.update()  //Assuming update is successful
    dw_2.update()  //Assuming update failed
    dw_3.update()  //Assuming update is successful
    Commit using SQLCA;
    

    The code can be revised as follows, to check the return status after each Update() call and explicitly execute COMMIT or ROLLBACK.

    SQLCA.Autocommit = false;
    
    If dw_1.update() = 1 then
     Commit using SQLCA;
    Else
      Rollback using SQLCA;
    End if 
    
    If dw_2.update() = 1 then
      Commit using SQLCA;
    Else
      Rollback using SQLCA;
    End if 
    
    If dw_3.update() = 1 then
      Commit using SQLCA;
    Else
      Rollback using SQLCA;
    End if