MyCommand rollback question

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
siberya
Posts: 23
Joined: Thu 23 Mar 2006 19:00

MyCommand rollback question

Post by siberya » Tue 04 Dec 2007 23:13

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.

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 05 Dec 2007 13:30

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.

kczhang
Posts: 1
Joined: Thu 06 Dec 2007 00:57

Post by kczhang » Thu 06 Dec 2007 01:16

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?

Post Reply