I still have some problems using transactions properly.
The idea is: A form is shown, the user enters data, saves it, prints it and closes the form. After saving the data he might change data and save them again. Only when the data is saved and printed everything is ok and when closing the form the data is committed.
Let's say I have 3 datamodules: two contain 2 TIBCQuery (QuOne1a, QuTwo1a, QuOne1b, QuTwo1b) components, one contains TIBCConnection (DBCon) and 2 TIBCTransaction (DBTr, DBTrUpd) components.
The TIBCConnection component has AutoCommit=false, DefaultTransaction=DBTr.
The TIBCQuery components have AutoCommit=false, Transaction=DBTr, UpdateTransaction=DBTrUpd.
The QuOne1a and QuTwo1a are used to insert data into tables TBLONE and TBLTWO. QuOne1b and QuTwo1b are used to provided the data from TBLONE and TBLTWO for printing reports.
QuOne1a and QuTwo1a are only opened and used to insert data when the user entered data into edit fields and clicked 'save'. So 'open', 'insert', QuOne1a.FieldByName('XYZ').AsString:='abcde'..., QuTwo1a.FieldByName('XXYY').AsInteger:=1234..., 'post' and 'close' are called.
Kind of (abstract):
Code: Select all
procedure FormShow; begin DBTrUpd.StartTransaction; ... end; procedure OnSaveDataClick; begin With QuOne1a do begin Open; Insert; FieldByName('XXX').Value:=Edit1.Text; FieldByName('XXY').Value:=Edit2.Text; FieldByName('XXZ').Value:=StrToInt(Edit3.Text); Post; Close; end; With QuTwo1a do begin Open; Insert; FieldByName('YYX').Value:=StrToInt(Edit4.Text); FieldByName('YYY').Value:=StrToFloat(Edit5.Text); FieldByName('YYZ').Value:=Edit6.Text; Post; Close; end; end; procedure OnPrintClick; begin QuOne1b.Open; QuTwo1b.Open; PrintReport; QuOne1b.Close; QuTwo1b.Close; end; procedure FormClose; begin if AllOk then DBTrUpd.Commit else DBTrUpd.Rollback; end;
Where is my misunderstanding of how transactions work in this case?