Better Place To Starting Transaction

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
simbahmerapi
Posts: 2
Joined: Mon 26 Oct 2009 16:16

Better Place To Starting Transaction

Post by simbahmerapi » Mon 05 Apr 2010 02:12

hello...
I try to develop a small application with unidac, just for practice n experience. I make a data form with 5 button. in INSERT button on click I just write :

Code: Select all

   UniTableMast.Insert;
and in POST on click I write :

Code: Select all

try
 If not UniTrans1.InTransaction then 
 Unitrans1.StartTransaction;
 UniTableMast.Post;
 UniTableDet.Insert;
 UniTableDet.Post;
 If UniTrans1.InTransaction then 
 Unitrans1.Commit;
except  
 If UniTrans1.InTransaction then 
 Unitrans1.Rollback;
end;
my friend said that this procedure is bad because I start the transaction after INSERT command (in SAVE button). But if I call StartTransaction before INSERT command (on INSERT button), it's could be user take too long before post the data. Which one is the better option in Unidac, and please give some explanation. Or if there is another better way, please teach me (but still use DataControl component).
Thank's very much for all your attention

bork
Devart Team
Posts: 649
Joined: Fri 12 Mar 2010 07:55

Post by bork » Tue 06 Apr 2010 07:11

Hello

Any changes to database are applied on the Post method (except the cashed updates mode). The Insert method adds a new record to UniTable or UniQuery but this record isn't added to a database. Record will be added to the database after the Post method execution only.

So you can start a transaction after the Insert method and before the Post method if you don't want to keep open transaction for a long time.

Post Reply