I try use transaction but rollback does not roll back
Posted: Tue 20 May 2008 09:04
I try the code below, to insert two rows and then undo it by a rollback, but the rows stays in the database. I try find an easy way to bundle some inserts, updates in a transaction to keep them consistent so either all executes, or none. How should i do this? Is it the execute that is wrong?
I use borland delphi 2007, and mydac 5.20.1.15
I do this:
Try
MyConnection1.StartTransaction;
MyQuery1.Close;
MyQuery1.SQL.Clear;
MyQuery1.SQL.Text :='insert test(codetype,code) value("type3","code3")';
MyQuery1.Execute;
MyQuery1.Close;
MyQuery1.SQL.Clear;
MyQuery1.SQL.Text :='insert test(codetype,code) value("type4","code4")';
MyQuery1.Execute;
MyConnection1.Rollback;
// MyConnection1.commit;
except
MyConnection1.Rollback;
end;
end;
I use borland delphi 2007, and mydac 5.20.1.15
I do this:
Try
MyConnection1.StartTransaction;
MyQuery1.Close;
MyQuery1.SQL.Clear;
MyQuery1.SQL.Text :='insert test(codetype,code) value("type3","code3")';
MyQuery1.Execute;
MyQuery1.Close;
MyQuery1.SQL.Clear;
MyQuery1.SQL.Text :='insert test(codetype,code) value("type4","code4")';
MyQuery1.Execute;
MyConnection1.Rollback;
// MyConnection1.commit;
except
MyConnection1.Rollback;
end;
end;