commit and rollback buttons on a vcl form
commit and rollback buttons on a vcl form
I have 2 DBGrids connected by 2 OraDatasources and populated by 2 OraQuery(ies) connected to 1 OraSession.
I would like to have 2 buttons on the form : 1. Commit changes. 2 Rollback changes.
When I enter data into the grid the database is auto updated by default.
Can I please have a simple recipe for which component's properties must be changed to achieve the desire functionality:
* user can change local data on either grid back and forth as often as they want but only when the users presses "commit" button is the database on the server updated. When the rollback button is pressed I want to rollback leave the data on the db unchanged and exit the form.
Thanks
I would like to have 2 buttons on the form : 1. Commit changes. 2 Rollback changes.
When I enter data into the grid the database is auto updated by default.
Can I please have a simple recipe for which component's properties must be changed to achieve the desire functionality:
* user can change local data on either grid back and forth as often as they want but only when the users presses "commit" button is the database on the server updated. When the rollback button is pressed I want to rollback leave the data on the db unchanged and exit the form.
Thanks
Re: commit and rollback buttons on a vcl form
Hello,
Two approaches can be used to solve your problem:
1) Transaction mechanism — prior to making changes call the OraSession.StartTransaction method, after making changes call the OraSession.Commit method in order to save data, and call OraSession.Rollback to cancel changes.
2) CachedUpdates mode — for this, the CachedUpdates property of OraQuery must be set to True. In this mode all changes will be saved to a DataSet, in order to save changes in the database you will have to call the OraQuery.ApplyUpdates method, or OraQuery.CancelUpdate to cancel changes.
Two approaches can be used to solve your problem:
1) Transaction mechanism — prior to making changes call the OraSession.StartTransaction method, after making changes call the OraSession.Commit method in order to save data, and call OraSession.Rollback to cancel changes.
2) CachedUpdates mode — for this, the CachedUpdates property of OraQuery must be set to True. In this mode all changes will be saved to a DataSet, in order to save changes in the database you will have to call the OraQuery.ApplyUpdates method, or OraQuery.CancelUpdate to cancel changes.
Re: commit and rollback buttons on a vcl form
Thank you - I appreciate your response. I will test your solutions.
Re: commit and rollback buttons on a vcl form
Couldn't they also just turn the AutoCommit property off on the query and session objects? Of course then they'd have to handle the transactions themselves, but it sounds like what they'd like to do.
-Mark
-Mark
Re: commit and rollback buttons on a vcl form
To me it is natural to present the data to the user (in this example 2 Grids); allow the user to manipulate all the data as he wishes on the form and then let the user decide if he is happy with the changes he has made on the form and then "commit" .. or conclude no he would rather escape and leave everything unchanged (Rollback).
When a user opens a Word document for example, they work on a copy of the the document that is on disk and at the end of his word sessions decides to do a "FILE - EXIT". Word then asks if the user wants to 'save' (=commit) all changes OR 'cancel' (=rolback) and thus cancel all his current work and leave the disk version of the document unaltered.
I am a little surprised as to the default behaviour of ODAC's OraSession, Ora DataSource, OraQuery and DBGrid. It seems as if the data is "committed" as I exit each DBGrid Cell. For me, this is very UNOracle behaviour. For me, Changes made to data in an oracle are temporary until Oracle is issued with a 'commit'. Anyway, I am new to Delphi and accept the need to "Start a transaction" explicitly and then explicity commit or roll it back.
I suspect that the "Transaction Mechanism" approach is the way to go in my exmaple .. as I need ALL my code to be consistent for ALL my forms I write; and I suspect that code for "Transaction Mechanism" will be more obvious in my Delphi code.
The CachedUpdates option on the Query component may not be obvious to other developers who may later work on my code.
If I follow the "Transaction Mechanism" approach will user nr 2 notice anything when they access data that is currently in a transaction by user nr 1?
Thanks again for your replies.
When a user opens a Word document for example, they work on a copy of the the document that is on disk and at the end of his word sessions decides to do a "FILE - EXIT". Word then asks if the user wants to 'save' (=commit) all changes OR 'cancel' (=rolback) and thus cancel all his current work and leave the disk version of the document unaltered.
I am a little surprised as to the default behaviour of ODAC's OraSession, Ora DataSource, OraQuery and DBGrid. It seems as if the data is "committed" as I exit each DBGrid Cell. For me, this is very UNOracle behaviour. For me, Changes made to data in an oracle are temporary until Oracle is issued with a 'commit'. Anyway, I am new to Delphi and accept the need to "Start a transaction" explicitly and then explicity commit or roll it back.
I suspect that the "Transaction Mechanism" approach is the way to go in my exmaple .. as I need ALL my code to be consistent for ALL my forms I write; and I suspect that code for "Transaction Mechanism" will be more obvious in my Delphi code.
The CachedUpdates option on the Query component may not be obvious to other developers who may later work on my code.
If I follow the "Transaction Mechanism" approach will user nr 2 notice anything when they access data that is currently in a transaction by user nr 1?
Thanks again for your replies.
Re: commit and rollback buttons on a vcl form
Hello,
Automatic Commit after the Post method call has been implemented for the sake of users' convenience, if you want to manage transactions yourself, you can explicitly start and commit transactions as required. Regardless of whether you use CashedUpdates or transactions, all changes made by a user will not be visible to other users until the Commit or ApplyUpdates methods are called.
Automatic Commit after the Post method call has been implemented for the sake of users' convenience, if you want to manage transactions yourself, you can explicitly start and commit transactions as required. Regardless of whether you use CashedUpdates or transactions, all changes made by a user will not be visible to other users until the Commit or ApplyUpdates methods are called.
Re: commit and rollback buttons on a vcl form
Thank you for your explanations.
Re: commit and rollback buttons on a vcl form
Hello,
If you have any other questions, feel free to contact us.
If you have any other questions, feel free to contact us.