Commit and RollBack in PB

Source: Internet
Author: User

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
......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.