TPQConnection.Close(true) doesn't work if connection to server is severed

Original Reporter info from Mantis: luca @olivluca
  • Reporter name: Luca Olivetti

Description:

With the parameter ForceClose:=true Close should ignore errors while closing the connection, but in case of a TPQConnection (postgresql server) it raises an exception so it's impossible to reopen the connection.

Steps to reproduce:

  1. Create a table test in a postgresql database
    create table test(c1 integer, c2 integer);
    insert into test values (1,2);
    insert into test values (3,4);

  2. In the attached lazarus project adjust the parameters of the PQConnection1 component in order to connect to the postgresql server

  3. Press the BtRefresh button to refresh the table

  4. stop and restart the postgresql server

  5. Now pressing the BtRefresh fails (as expected)

  6. The BtReconnect button should close and reopen the connection but it raises an exception instead.

Project project1 raised exception class 'EPQDatabaseError' with message:
PQConnection1: connection pointer is NULL
(PostgreSQL:)

In file 'fcl-db/src/sqldb/postgres/pqconnection.pp' ad line 725:
raise E;

Additional information:

I tested both under win32 and linux64/qt (I don't think it's relevant).

See the mailing list thread starting here:
http://lists.lazarus-ide.org/pipermail/lazarus/2018-May/234734.html

Mantis conversion info:

  • Mantis ID: 33737
  • Version: 3.0.4
  • Fixed in version: 3.3.1
  • Target version: 3.2.0