I haven't looked into the codes here in depth, but I'd like to mention basic structure of SQL databases, which I had difficulty when I first entered the SQL world.
What are called as TDataSet and its decendants like TSQLQuery, etc. are separate entities in the of SQL DB world. If you are operating with local tables, e.g. csv files, then the TDataSets (TCSVDataSet, TBufDataSet, etc.) are directly linked to the physical DB on HDD.
But in SQL, once you open a dataset, like
SQLQuery.Transaction.Active := True;
SQLQuery.SQL.Text := 'select * from table1';
SQLQuery.Open;
(SQLQuery.Transaction as TSQLTransaction).RollbackRetaining; // with this, Server DB file is disconnected.
You'd better think that this makes a copy of the subset of the table (the whole table in this case) from physical table on HDD.
And following operations on this dataset, like
SQLQuery.Edit;
SQLQuery.FieldByName('f1').AsInteger := 199999;
SQLQuery.Post;
operate only on the TSQLQuery, which is "COPY" of original table. Here, you may insert a record and then cancel it.
If all options are manual (nothing is done automatically), then you should start transaction yourself again, because this is related with ServerDB, not local TDataSet.
SQLQuery.Transaction.Active := True;
SQLQuery.ApplyUpdates;
(SQLQuery.Transaction as TSQLTransaction).Commit; // with this, Server DB file is disconnected.
If you rollback transaction after ApplyUpdates, then the changes will not be saved to the permanent DB.
And "commiting" after ApplyUpdates will close SQLQuery. If you call CommitRetaining, then the updates will be applied (changes will be saved to the permanent DB), but the SQLQuery DataSet will still remain open (as dsBrowse).
And there are options like AutoApplyUpdates, AutoCommit, etc. autocommit, etc. Possibly AutoApplyUpdates will carry out ApplyUpdate as soon as "post" is done. With AutoCommit, any updates to the permanent DB will be committed automatically, I guess. Using these options you can alleviate starting and stopping transactions.
You may already know on these. Sorry if you do. If not, please check your codes step by step.
========================
I made mistake. I thank rvk for correcting them (below).