Page 1 of 1

I try use transaction but rollback does not roll back

Posted: Tue 20 May 2008 09:04
by midnite
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;

Posted: Tue 20 May 2008 15:10
by midnite
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.

Posted: Wed 21 May 2008 10:32
by Dimon
This is true. MySQL does not support the transactions with MyISAM tables, and therefore you should use InnoDB.