Many transactions and One Connection
Posted: Fri 13 Jul 2018 20:07
Hi!! I've a problem with many transactions with one connection.
I explain :
1. I ´ve a. 2 DataModules: DataModule1 and DataModule2.
b. Transactions(TIBCTransaction), 3 components ( tranUpdate1, tranUpdate2, tranUpdate3)
c. TIBCQuery, 3 components
vQuery1 ( Insert data in table1, with Autocommit Property := false)
vQuery2 ( update data in table2, with Autocommit Property := false)
vQuery3( update data in table3, with Autocommit Property := false)
d.One TIBCConnection contains DBCon ( Interbase XE7).
2.I create and define:
tranUpdate1 := TIBCTransaction.Create(DBCon)
tranUpdate2:= TIBCTransaction.Create(DBCon)
tranUpdate3 := TIBCTransaction.Create(DBCon)
So 3 transactions are conected one DBCon (TIBCConnection):
tranUpdate1.DefaultConnection:= DBCon;
tranUpdate2.DefaultConnection:= DBCon;
tranUpdate3.DefaultConnection:= DBCon;
3 transactions opened/Closed at the same time
3 transactions are closed by a Commit/rollbact action.
3.Open Connection: DB.Open
4..I create and define:
vQuery1 := TIBCQuery.Create(nil);
vQuery2 := TIBCQuery.Create(nil);
vQuery3 := TIBCQuery.Create(nil);
vQuery1 .Update Transaction:= tranUpdate1;
vQuery2 .Update Transaction:= tranUpdate2;
vQuery3 .Update Transaction:= tranUpdate3;
vQuery1.Open
vQuery2.Open
vQuery3.Open
5. Start Transactions
tranUpdate1.StartTransaction
tranUpdate2.StartTransaction
tranUpdate3.StartTransaction
6. Prepare and execute vQuery1, vQuery2 and vQuery3, but if any vQuery? fail and
control Connection then
If (tranUpdate1.Active = false) or (tranUpdate2.Active = false) or
(tranUpdate3.Active = false) or ( DBCon.TransactionCount<> 3) then
tranUpdate1.Rollback
tranUpdate2.Rollback
tranUpdate3.Rollback
But If (tranUpdate1.Active= true ) or (tranUpdate2.Active = true) or
(tranUpdate3.Active= true) or DBCon.TransactionCount = 3 then
tranUpdate1.Commit
tranUpdate2.Commit
tranUpdate3.Commit
But i don´t know DBCon.Default Transactions, which transaction I choose?
DBCon.Default Transactions:= ¿? ( TranUpdate1 or TranUpdate2 or TranUpdate3?
Thanks in advance
Angélica ( Arizmendi Team)
I explain :
1. I ´ve a. 2 DataModules: DataModule1 and DataModule2.
b. Transactions(TIBCTransaction), 3 components ( tranUpdate1, tranUpdate2, tranUpdate3)
c. TIBCQuery, 3 components
vQuery1 ( Insert data in table1, with Autocommit Property := false)
vQuery2 ( update data in table2, with Autocommit Property := false)
vQuery3( update data in table3, with Autocommit Property := false)
d.One TIBCConnection contains DBCon ( Interbase XE7).
2.I create and define:
tranUpdate1 := TIBCTransaction.Create(DBCon)
tranUpdate2:= TIBCTransaction.Create(DBCon)
tranUpdate3 := TIBCTransaction.Create(DBCon)
So 3 transactions are conected one DBCon (TIBCConnection):
tranUpdate1.DefaultConnection:= DBCon;
tranUpdate2.DefaultConnection:= DBCon;
tranUpdate3.DefaultConnection:= DBCon;
3 transactions opened/Closed at the same time
3 transactions are closed by a Commit/rollbact action.
3.Open Connection: DB.Open
4..I create and define:
vQuery1 := TIBCQuery.Create(nil);
vQuery2 := TIBCQuery.Create(nil);
vQuery3 := TIBCQuery.Create(nil);
vQuery1 .Update Transaction:= tranUpdate1;
vQuery2 .Update Transaction:= tranUpdate2;
vQuery3 .Update Transaction:= tranUpdate3;
vQuery1.Open
vQuery2.Open
vQuery3.Open
5. Start Transactions
tranUpdate1.StartTransaction
tranUpdate2.StartTransaction
tranUpdate3.StartTransaction
6. Prepare and execute vQuery1, vQuery2 and vQuery3, but if any vQuery? fail and
control Connection then
If (tranUpdate1.Active = false) or (tranUpdate2.Active = false) or
(tranUpdate3.Active = false) or ( DBCon.TransactionCount<> 3) then
tranUpdate1.Rollback
tranUpdate2.Rollback
tranUpdate3.Rollback
But If (tranUpdate1.Active= true ) or (tranUpdate2.Active = true) or
(tranUpdate3.Active= true) or DBCon.TransactionCount = 3 then
tranUpdate1.Commit
tranUpdate2.Commit
tranUpdate3.Commit
But i don´t know DBCon.Default Transactions, which transaction I choose?
DBCon.Default Transactions:= ¿? ( TranUpdate1 or TranUpdate2 or TranUpdate3?
Thanks in advance
Angélica ( Arizmendi Team)