I use Mydac Trial version and delphi 7.
My tables are innoDB.
In my code, I'm trying to use transactions, but it does not work properly:
when I rollback a transaction, it does nothing.
MyCommand.AutoCommit := False;
Try
MyConnection.StartTransaction;
MyCommand.Execute;
except
MyConnection.Rollback; <-- not work?
Exit;
end;
I try to set autocommit = 0 with a TMyCommand component, but when I interrogate the TMyServerControl component, autocommit is always set to true.
MyCommand rollback question
There is no need to change the AutoCommit value, because if you start a transaction explicitly, it will not be committed or rolled back until you call Commit or Rollback explicitly.
Do you consider that Rollback is called only if MyCommand.Execute raises an exception?
There should be also a call to MyConnection.Commit in your code.
Do you consider that Rollback is called only if MyCommand.Execute raises an exception?
There should be also a call to MyConnection.Commit in your code.
self.MyConnection1.StartTransaction;
try
self.MyQuery1.Close;
self.MyQuery1.SQL.Clear;
self.MyQuery1.SQL.Text :='insert tbl_hw_test2(test_name) value(''11'')';
self.MyQuery1.Execute;
self.MyQuery1.Close;
self.MyQuery1.SQL.Clear;
self.MyQuery1.SQL.Text :='insert tbl_hw_test(test_id) value(''1'')';
self.MyQuery1.Execute;
self.MyConnection1.Commit;
except
self.MyConnection1.Rollback;
end;
When table(tbl_hw_test) unusual,table(tbl_hw_test2) no way rollback,This is where there are problems?
try
self.MyQuery1.Close;
self.MyQuery1.SQL.Clear;
self.MyQuery1.SQL.Text :='insert tbl_hw_test2(test_name) value(''11'')';
self.MyQuery1.Execute;
self.MyQuery1.Close;
self.MyQuery1.SQL.Clear;
self.MyQuery1.SQL.Text :='insert tbl_hw_test(test_id) value(''1'')';
self.MyQuery1.Execute;
self.MyConnection1.Commit;
except
self.MyConnection1.Rollback;
end;
When table(tbl_hw_test) unusual,table(tbl_hw_test2) no way rollback,This is where there are problems?