But you can also set auto-commit transactions in the TSQLQuery options:
SQLQuery1.Options := [sqoAutoApplyUpdates, sqoAutoCommit];
IMO there is no need to have seperate transaction Objects for each Query. A single Transaction Object connected to the connection object will suffice. So you get rid of any lines dealing with transactions except a last one that closes the transaction object before closing the connection object.
Where do you store your connection Object including the connections transaction?
Mainform or Data Module?
Do you know which strings are sendt and received to and from your database?
Have you implemented a log file feature where you can see this?
some kind of code example by aircode:
//put this in your datamodules initializing procedure
SQLConn.OnLog:=@DoSQLLog;
SQLConn.LogEvents:=LogAllEventsExtra; //either LogAllEvents or LogAllEventsExtra
procedure TctSQLconnect.DoSQLLog(Sender: TSQLConnection; EventType: TDBEventType;
const Msg: String);
var
f:TextFile;
sFileName:string;
LogString:string;
begin
if not FbLogSQL then exit;
case EventType of
detCustom: LogString:='Custom';
detPrepare: LogString:='Prepare';
detExecute: LogString:='Execute';
detFetch: LogString:='Fetch';
detCommit: LogString:='Commit';
detRollBack: LogString:='RollBack';
detParamValue: LogString:='ParamValue';
detActualSQL: LogString:='ActualSQL';
else ;
LogString:='Unknown';
end;
Logstring:=Logstring+' '+ Msg;
WriteToSQLLog(Logstring); //write log to file immediately
end;
maybe you get a trace where the database locks.
Usually a SQLite database is locked when another open access to the SQLite database occupies the access. That can be internal (when another/second SQL connection object tries to manipulate data while the primary connection object is not yet closed) or external (if some kind of "DB Browser for SQLite" or "Heidi" blocks the database)
BTW: a common closing of SQLQueries in one procedure of the main form is obsolete for me.
In my mind every form takes care of opening and closing all components it needs. Including database components as TSQLQuery and TDatasource.
In the Event OnFormClose or even better OnCloseQuery you can do all this and tidy up your form. This way all work is done with am mere close of the each form.
Even when closing the application with several open forms this strategy closes all open database components and even the connection securely.