Recent

Author Topic: TPQConnection create a second access  (Read 4494 times)

Michl

  • Full Member
  • ***
  • Posts: 226
TPQConnection create a second access
« on: September 18, 2013, 10:29:45 pm »
Hi,

this code works fine (Zeos).
Code: [Select]
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if ZConnection1.Connected then begin
        ZQuery1.Active:=False;
        ZConnection1.Connected:=False;
      end else begin
        ZConnection1.Connected:=True;
        ZQuery1.Active:=True;
      end;
    end;
first click on button -> 1 access is created
second click -> access is closed

the same procedure with TPQConnection and TSQLQuery create 2 hits (first click)
second click 1 access is closed, 1 is active

I tried follow code to delete the second
Code: [Select]
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if PQConnection1.Connected then begin
        SQLQuery1.Active:=False;
        SQLQuery1.Close;
        SQLQuery1.Destroy;
        SQLQuery1.Free;
        PQConnection1.CloseDataSets;
        PQConnection1.CloseTransactions;
        PQConnection1.Connected:=False;
        PQConnection1.Close;
        PQConnection1.Free;
      end else begin
        PQConnection1.Connected:=True;
        SQLQuery1.Active:=True;
      end;
    end;
nothing works

Does anybody know, how to close the second access?

I add two projects, where you can see, what I mean (you have to enter your databasename, username, password and query.sql)

Maybe it´s a bug, I use Lazarus 1.1 r42453 FPC 2.7.1 i386-win32-win32/win64

Here is a crosspost http://www.lazarusforum.de/viewtopic.php?f=17&t=7218
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: TPQConnection create a second access
« Reply #1 on: September 20, 2013, 08:32:11 am »
This was a design decision taken in sqldb. Since you can have only one transaction per db connection in PostGres, a new connection is created per transaction and disconnected after a COMMIT or ROLLBACK. When opening a TPQConnection, a connection to the DB is established which is not re-used.
 
This has been fixed in 2.7.1 (trunk). A connection pool is used and idle connections (no active transaction) are returned to the pool. This has also the advantage that the number of re-connections (and its authorization overhead) is limited enormously when a lot of small transactions are used. 

Michl

  • Full Member
  • ***
  • Posts: 226
Re: TPQConnection create a second access
« Reply #2 on: September 20, 2013, 11:38:26 am »
Ok, I use FPC 2.7.1.

My problem is, when I want to make a Backup, the simplest way is to drop my database in PG and load the Backup (no double items in there and wrong items are deleted). But to drop the database is not possible, cause I can not delete the dead access. What can I do?

My linked project shows the dead access, if it helps?!
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: TPQConnection create a second access
« Reply #3 on: September 21, 2013, 08:21:16 am »
Dit you update your trunk recently? 2 days ago a bug was solved that caused connections to be "lost" in the pool?

Michl

  • Full Member
  • ***
  • Posts: 226
Re: TPQConnection create a second access
« Reply #4 on: September 22, 2013, 12:26:46 am »
I would test it, but I´m failed.

I can build a Lazarus (42906) with the actual fpcbuild, but by compiling a own project there a to many bugs, which I don not know to handle :(

So, I will wait for a snapshot...

Thank you very much, for your attention and work!
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

 

TinyPortal © 2005-2018