how to control commit/rollback

how to control commit/rollback

Postby Hans » Sun 11 Sep 2005 07:26

When using multiple QRY and TBL components on a Fom I wonder how I can control commit/rollback. I created a wizard using a pagecontrol and want to be able to commit/rollback all updates/inserts in the last page but I donot understand how I can see if anything has been updated and/or inserted. I look at the 'modified' property but I believe if I do a Post in an earlier page the rollback seems to be ignored.

Is there an example available or can someone explain this? (Do I have to use cachedUpdates???

Posts: 52
Joined: Wed 24 Aug 2005 20:05

Postby swierzbicki » Mon 12 Sep 2005 06:27

When creating your wizard :
execute this statement:

Now, let your user do what he want to do....

On the finich button :

On the cancel button
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Postby GEswin » Mon 12 Sep 2005 08:41

Perhaps a better solution;

1) On FormCreate -> myConnection.StartTransaction;
2) On Accept -> if myConnection.InTransaction then myConnetion.Commit;
3) On Cancel -> if myConnection.InTransaction then myConnetion.RollBack;

Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain

Postby Ikar » Mon 12 Sep 2005 11:34

First of all, you should use transaction-safe table type (InnoDB). Use methods TMyConnection.StartTransaction etc to transactional control. May be you need to read help about CachedUpdates mode. Also, you can see CachedUpdates Demo
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Postby Hans » Sun 18 Sep 2005 07:38

Thank you all for your replies! It is very nice to get some support of others.
I believe I understand the transaction mechanism now. I think I have to write some code to find out if something has changed in order to ask the user if he/she wants to save changes. It seems that the DataSet->modified flag refers to the active record only. Since I am using multiple DataSets and the user can edit multiple records, I believe I have to create my own modified flag per DataSet which tells me if one ore more records in a DataSet has been changed.

i.e. if you change a record in a grid a post is done after you TAB the last field. Than the next record is selected and the modified flag says nothing has been changed, since it only applies to the current record. I will have to do some administration using OnPost and OnCancel.
Posts: 52
Joined: Wed 24 Aug 2005 20:05

Return to MySQL Data Access Components