[Lazarus] SQLTransaction won't start

Petr Hlozek petr at ok2cqr.com
Fri Mar 14 12:20:11 CET 2014


Hi,

I use TMySQL55Connection, TSQLTransaction and TSQLQuery. I always get
Transaction is NOT active.

here is the code:

procedure TForm1.Button1Click(Sender: TObject);
var
  db : TMySQL55Connection;
  q  : TSQLQuery;
  tr : TSQLTransaction;
begin
  db := TMySQL55Connection.Create(nil);
  q  := TSQLQuery.Create(nil);
  tr := TSQLTransaction.Create(nil);
  try try
    db.DatabaseName := 'test';
    db.UserName     := 'root';
    db.Password     := 'passwd';
    db.Open;

    q.DataBase    := db;
    tr.DataBase   := db;
    q.Transaction := tr;

    tr.StartTransaction;
    try
      if tr.Active then
        Writeln('Transaction is active')
      else
        Writeln('Transaction is NOT active')
    finally
      tr.Rollback
    end
  except
    on E: Exception do
      Writeln(E.Message)
  end
  finally
    q.Close;
    FreeAndNil(q);
    FreeAndNil(tr);
    FreeAndNil(db)
  end
end;

or http://pastebin.com/qmCMfKMh

Ubuntu 13.10, mysql 5.5, Lazarus 1.0.10, FreePascal 2.6.2-5. The test
table is in InnoDB:

CREATE TABLE test_table (
  id bigint NOT NULL AUTO_INCREMENT PRIMARY KEY,
  myfield varchar(100) DEFAULT ''
) ENGINE='InnoDB' COLLATE 'utf8_bin';


Could you help me, please? Thanks a lot.


Petr




More information about the Lazarus mailing list