Page 1 of 1

Better Place To Starting Transaction

Posted: Mon 05 Apr 2010 02:12
by simbahmerapi
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

Posted: Tue 06 Apr 2010 07:11
by bork
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.