commit and rollback buttons on a vcl form

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
nclark
Posts: 19
Joined: Wed 10 Oct 2007 11:45
Location: Norway

commit and rollback buttons on a vcl form

Post by nclark » Tue 16 Jul 2013 15:07

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: commit and rollback buttons on a vcl form

Post by AlexP » Wed 17 Jul 2013 11:41

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.

nclark
Posts: 19
Joined: Wed 10 Oct 2007 11:45
Location: Norway

Re: commit and rollback buttons on a vcl form

Post by nclark » Wed 17 Jul 2013 11:59

Thank you - I appreciate your response. I will test your solutions.

MarkF
Posts: 211
Joined: Thu 02 Mar 2006 14:55

Re: commit and rollback buttons on a vcl form

Post by MarkF » Wed 17 Jul 2013 12:08

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

nclark
Posts: 19
Joined: Wed 10 Oct 2007 11:45
Location: Norway

Re: commit and rollback buttons on a vcl form

Post by nclark » Wed 17 Jul 2013 12:31

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.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: commit and rollback buttons on a vcl form

Post by AlexP » Thu 18 Jul 2013 12:39

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.

nclark
Posts: 19
Joined: Wed 10 Oct 2007 11:45
Location: Norway

Re: commit and rollback buttons on a vcl form

Post by nclark » Thu 18 Jul 2013 14:12

Thank you for your explanations.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: commit and rollback buttons on a vcl form

Post by AlexP » Thu 18 Jul 2013 15:25

Hello,

If you have any other questions, feel free to contact us.

Post Reply