libpq PQstatus failed

From: <philip(dot)howell(at)cit(dot)act(dot)edu(dot)au>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: libpq PQstatus failed
Date: 2001-03-14 04:57:23
Message-ID: 0103149845.AA984548938@mh-cit.cit.act.edu.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi

I'm having problems with the PQstatus function in the libpq library. It returns
CONNECTION_OK when I know that it is not. I used the followin test program and
method to test it:

------------------------

#include <stdlib.h>
#include <stdio.h>
#include "pgsql/libpq-fe.h"

PGconn *make_conn();

int main (int argc, char *argv[])
{
PGconn *conn;

conn = make_conn();

while (fgetc(stdin) != 'q')
{
printf("Connection status... ");
if (PQstatus(conn) != CONNECTION_OK) {
printf("BAD\n");
PQreset(conn);
} else {
printf("OK\n");
}

}
return(0);
}

PGconn *make_conn()
{
PGconn *conn;

conn = PQconnectdb("hostaddr = 161.50.16.173 dbname = mydb user = me
password = foo");
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr,"Failed to connect to database\n");
fprintf(stderr,"%s\n",PQerrorMessage(conn));
PQfinish(conn);
exit(1);
}
return(conn);
}

-------------------------

I ran the program (with my postgreSQL server up and running) and hit <return> a
few times, I got the following expected output:

>
> Connection status... OK
>
> Connection status... OK
>
> Connection status... OK

Then I stoped the network (eth0) on the postgreSQL server and hit <return> again
and still got

> Connection status... OK

as the output. I epected the output to be:

> Connection status... BAD

However Trying to execute the programe with the postgreSQL server offline
resulted in the expected error messages, so it seems that in this case the
status was detected successfully.

SYSTEM INFORMATION:
===================

postgreSQL Server:
Hardware: i386
OS Linux RedHat 6.2
Postgres was installed from RPMs version 7.0.3-2

Client Machine
Hardware: i386
OS: Linux RedHat 6.2
RPMs installed:
postgresql-devel-7.0.3-2
postgresql-7.0.3-2

I compiled the program with:

gcc -Wall -o test test.c -lpq

Regards
Phil

Browse pgsql-bugs by date

  From Date Subject
Next Message pgsql-bugs 2001-03-14 05:16:23 Checking PQstatus (libpq) returns CONNECTION_OK when it is not.
Previous Message Kemal Bayram 2001-03-13 22:29:10 modulo operator bug?