Page 1 of 1

MyCommand rollback question

Posted: Tue 04 Dec 2007 23:13
by siberya
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.

Posted: Wed 05 Dec 2007 13:30
by Antaeus
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.

Posted: Thu 06 Dec 2007 01:16
by kczhang
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?