PBCommit and RollBack in
All those who use PowerBuilder must have used Commit (Commit transaction statement) and RollBack (RollBack transaction Statement ). I would like to share with you the following:
1. Submit the transaction statement COMMIT
The COMMIT statement submits transactions to complete physical modification of the database. After the statement is executed, all previously opened CURSOR and PROCEDURE are closed and a new transaction starts. The syntax format of the COMMIT statement is:
COMMIT {USING TransactionObject };
Among them, TransactionObject is the transaction object name that needs to be permanently updated to the database. If it is missing, use the transaction object SQLCA.
2. roll back the transaction statement ROLLBACK
ROLLBACK discards all database operations since the previous COMMIT, ROLLBACK, or CONNECT statement, closes all cursors and processes, and starts a new transaction. The syntax format is:
ROLLBACK {USING TransactionObject };
Specifically, TransactionObject is the diagonal name of the transaction, and SQLCA is used when the transaction object is missing;
Note: InPBThe most widely usedDatastoreBut not cleared during Commit or RollBack.Datastore.
Case:
......
//Data Update
Ll_returnvalue = lds_detail.update (True, true)
If ll_returnvalue> 0 then
St_text.text = 'store' + ls_site + 'detail. DBF Data Processing successful! '
Ll_returnvalue = lds_inventory.update (True, true)
If ll_returnvalue> 0 then
St_text.text = 'the data warehouse has been processed successfully. Submitting... '
Commit using sqlca;
St_text.text = 'congratulations, data is submitted successfully! '
F_readwrite ('R ')
Else
Rollback using SQLCA;
F_readwrite ('E ')
End If
Else
Rollback using SQLCA;
F_readwrite ('E ')
End If
......
Lds_detail (SalesDatastore), Lds_inventory (warehouseDatastore) If an lds_detail update fails during a loop operation and the rollback using sqlca continues the loop, the lds_detail will be assigned a new value due to the function, at this time, the content in lds_inventory is not updated, but the content is still in progress. An unexpected error occurs when the data in the loop continues. The data is inconsistent.
Solution:
You can release (destroy) or (reset) after each rollback operation)Datastore.
Correct code:
......
//Data Update
Ll_returnvalue = lds_detail.update (True, true)
If ll_returnvalue> 0 then
St_text.text = 'store' + ls_site + 'detail. DBF Data Processing successful! '
Ll_returnvalue = lds_inventory.update (True, true)
If ll_returnvalue> 0 then
St_text.text = 'the data warehouse has been processed successfully. Submitting... '
Commit using sqlca;
St_text.text = 'congratulations, data is submitted successfully! '
F_readwrite ('R ')
Else
Rollback using sqlca;
Destroy lds_inventory // or lds_inventory.reset ()
F_readwrite ('E ')
End if
Else
Rollback using sqlca;
Destroy lds_inventory // or lds_inventory.reset ()
F_readwrite ('E ')
End if
......