I try use transaction but rollback does not roll back

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
midnite
Posts: 2
Joined: Thu 24 Apr 2008 22:02

I try use transaction but rollback does not roll back

Post by midnite » 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;

midnite
Posts: 2
Joined: Thu 24 Apr 2008 22:02

Post by midnite » Tue 20 May 2008 15:10

I think i have it, I can not use MyISAM but have to use InnoDB as MySQL engine for the transactions to work. If anyone have something more to add, please do so.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 21 May 2008 10:32

This is true. MySQL does not support the transactions with MyISAM tables, and therefore you should use InnoDB.

Post Reply