I am using the code below but I'm not convinced it is correctly detecting an error and doing the rollback every time as the error message isn't shown. Please can somebody take a look at it and tell me if it should work OK and if not, how I should alter it to do what I want?
Code: Select all
sql := ''
+ 'START TRANSACTION; '
+  'Insert into ....'       // lots of statements that might cause an error
+  'Delete from ...  '  
etc
+ ' COMMIT; '  ;
try
 MyCommand1.SQL.Clear;
 MyCommand1.SQL.Add(sql);
 MyCommand1.Execute;
 //if we get here then the sql went OK 
except    //if we get here then the sql caused an error somewhere
     on E : Exception do
         begin
         showmessage('Error in transaction '); 
         MyCommand1..SQL.Clear ;
         MyCommand1..SQL.Add('ROLLBACK; ');
         MyCommand1..Execute;
         end; //on E : Exception
end; //try  - except