I am using the following:
begin
dbmodule.comenziQuery.SQL.Clear;
dbmodule.comenziQuery.SQL.Add('INSERT INTO `r33758pi_tipotask`.`arhiva` SELECT id, data, stare, client, telefon, email, detalii, observatii, pret, livrare, user, status FROM comenzi WHERE `id`='''+inttostr(dbmodule.comenziDataSetid.Value)+''';');
dbmodule.comenziQuery.ExecSQL(true);
dbmodule.comenziQuery.SQL.Clear;
dbmodule.comenziQuery.SQL.Add('DELETE FROM `r33758pi_tipotask`.`comenzi` WHERE `id`='''+inttostr(dbmodule.comenziDataSetid.Value)+''';');
dbmodule.comenziQuery.ExecSQL(true);
end;
Can anyone guide me on how to wrap this in a transaction? I've never used one before and I'm having difficulty understanding how to modify the code to add it.
I'm trying to add it in a transaction
as I've read it is good practice, since if 1 fails it won't execute at all.
I've tried following this guide Some Guide and subsequently using the begin transaction
and begin try
that are mentioned there but I'm guessing that's not intented for delphi code, or something..so no luck.
Hope the code is ok, please feel free to point out anything wrong I might have done so far.
Delphi, using Rad Studio 10 Seattle, TSQLQuery
- Server is mysql
- let me know in a comment if I left anything out and I will edit.