Recent

Author Topic: [Zeos] + [MySql] -> transaction does not rollback :(  (Read 6260 times)

Talker

  • New Member
  • *
  • Posts: 18
[Zeos] + [MySql] -> transaction does not rollback :(
« on: January 22, 2014, 12:43:59 pm »
Hi there!

I use MySql (v. 5.5.25) via Zeos DB components. Can not rollback operation by command ZQuery1.Connection.Rollback :(

In detail:
There is a form for editing a row from a table and there is a grid on the form with rows from a child table with buttons for add|edit|delete this child rows.
A TZConnection component's property AutoCommit = False and TransactionIsolationLevel = tiReadCommitted

I start a transaction before the form opening.
And I commit  the transaction on clicking <Ok> button and roll it back on <Cancel> button.

Code: [Select]
  frmFizGrid.ZQuery.Connection.StartTransaction;
  if ShowModal = mrOk then
    frmFizGrid.ZQuery.Connection.Commit
  else begin
    frmFizGrid.ZQuery.Connection.Rollback;
    ShowMessage('Calling "Rollback"');
  end;

I insert a row into the child table after the form is showing and transaction is started :
Code: [Select]
  ...
  ZQuery1.SQL.Add('insert into tbl (...) values (...)');
  ZQuery1.ExecSql;
  ...

Then I press <Cancel> button and I see a message 'Calling "Rollback"'.
But the new row in the child table doesn't disappear!

Could you please tell me what I'm doing wrong?

p.s. I've tried this with table types MyISAM and InnoDB
« Last Edit: January 22, 2014, 12:48:32 pm by Talker »

Zoran

  • Hero Member
  • *****
  • Posts: 1948
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: [Zeos] + [MySql] -> transaction does not rollback :(
« Reply #1 on: January 22, 2014, 02:19:39 pm »
Set AutoCommit to True and try then. You should not call StartTransaction when AutoCommit is False.

Here is what AutoCommit property actually means:
When AutoCommit property is True, this means that Zeos automatically commits transactions for each statement, but you can use StartTransaction to prevent auto commits.
When AutoCommit is False, you should not use StartTransaction because the transaction is automatically started, but it must be commited (or rolled back) explicetely.

Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Talker

  • New Member
  • *
  • Posts: 18
Re: [Zeos] + [MySql] -> transaction does not rollback :(
« Reply #2 on: January 23, 2014, 06:02:52 am »
Set AutoCommit to True and try then. You should not call StartTransaction when AutoCommit is False.
Oh, sorry! AutoCommit is set to True, not to False.  :-[

Zoran

  • Hero Member
  • *****
  • Posts: 1948
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: [Zeos] + [MySql] -> transaction does not rollback :(
« Reply #3 on: January 23, 2014, 06:34:39 am »
Could you post a simple application which shows the problem?
Swan, ZX Spectrum emulator https://github.com/zoran-vucenovic/swan

Talker

  • New Member
  • *
  • Posts: 18
Re: [Zeos] + [MySql] -> transaction does not rollback :(
« Reply #4 on: January 23, 2014, 01:32:09 pm »
I apologize, cause of the problem was incorrect child table's type - MyISAM.
Thanks a lot anyway!
« Last Edit: January 23, 2014, 01:37:08 pm by Talker »

 

TinyPortal © 2005-2018