Migrating from UniDAC to PgDAC

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
e-eduardo
Posts: 2
Joined: Fri 31 Mar 2017 14:09

Migrating from UniDAC to PgDAC

Post by e-eduardo » Fri 31 Mar 2017 14:17

I was used to work with UniDAC and Firebird and now I'm migrating to PgDAC and PostgreSQL, but some little things are weird for me. So, I wanna know how can I do to migrate the example below using PgDAC:

Code: Select all

procedure TForm1.UpdatingSomething;
var
  MyID: Integer;
begin
  SomethingWasUpdated := False;
  MyID := 15047;
  try
    UniTransaction1.StartTransaction;

    UniStoredProc1.Params[0].AsInteger := MyID;
    UniStoredProc1.Params[1].AsString := 'something';
    UniStoredProc1.Prepare;
    UniStoredProc1.ExecProc;

    UniStoredProc2.Params[0].AsDateTime := Now;
    UniStoredProc2.Params[1].AsInteger := MyID;
    UniStoredProc2.Params[2].AsInteger := 100;
    UniStoredProc2.Params[3].AsInteger := 912;
    UniStoredProc2.Params[4].AsString := 'Disabled';
    UniStoredProc2.Prepare;
    UniStoredProc2.ExecProc;

    UniTransaction1.Commit;
    SomethingWasUpdated := True;
  except
    on E: Exception do
    begin
      UniTransaction1.Rollback;
      ShowErrorMessage(E);
    end;
  end;
end;
Thanks!

azyk
Devart Team
Posts: 1021
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Migrating from UniDAC to PgDAC

Post by azyk » Tue 04 Apr 2017 09:46

In PgDAC to control a transaction use the StartTransaction/Commit/Rollback methods of the TPgConnection component:

Code: Select all

procedure TForm1.UpdatingSomething;
var
  MyID: Integer;
begin
  SomethingWasUpdated := False;
  MyID := 15047;
  try
    PgConnection1.StartTransaction;

    PgStoredProc1.Params[0].AsInteger := MyID;
    PgStoredProc1.Params[1].AsString := 'something';
    PgStoredProc1.Prepare;
    PgStoredProc1.ExecProc;

    PgStoredProc2.Params[0].AsDateTime := Now;
    PgStoredProc2.Params[1].AsInteger := MyID;
    PgStoredProc2.Params[2].AsInteger := 100;
    PgStoredProc2.Params[3].AsInteger := 912;
    PgStoredProc2.Params[4].AsString := 'Disabled';
    PgStoredProc2.Prepare;
    PgStoredProc2.ExecProc;

    PgConnection1.Commit;
    SomethingWasUpdated := True;
  except
    on E: Exception do
    begin
      PgConnection1.Rollback;
      ShowErrorMessage(E);
    end;
  end;
end;

Post Reply