Firedac Fdquery with Mysql Transaction.commit and rollback does not work

Asked

Viewed 354 times

-1

I am running a test with Fdconnection and Fdquery and Mysql database. In my test table there is only one field called key with Primary key. Running command below, rollback does not work.

Relate the item

  FdConnection1.TxOptions.AutoCommit:=false;
  FdConnection1.Connected:=true;
  try
    FdConnection1.StartTransaction;
    FdQuery1.SQL.Text:=('insert into teste (chave) values (:chave)');
    FdQuery1.ExecSQL('',['01']);
    FdQuery1.ExecSQL('',['01']);
    FDConnection1.Commit;
  except
    FDConnection1.Rollback;
    showMessage('Erro');
  end;

Running this command shows "error" message, but in the table you entered a record. It should be empty, right? If anyone can help, thank you.

1 answer

0

Make sure your table supports transactions, if this is the case you do a test using "Start Transaction", "Commit" and "Rollback" in Fdquery1’s SQL, instead of using Fdconnection’s.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.