Hi,

I shall try to write english well enough :)

I'm writing a GUI client to access my PostrgeSQL DB, with FLTK libraries. Sometimes, the client crashes.

I have written un source code, as little as possible, without FLTK libraries, to test the behavior of PQfinish(), and I noticed :

If no connexion has ever been made, [ PQstatus() retuns 'CONNECTION_BAD' ] , a call to PQfinish(...) does not do something wrong.
But il I connect with  PQsetdblogin(..), [ PQstatus returns 'CONNECTION_OK ], a first call to PQfinish(...) disconnects the client, [ PQstatus returns 'CONNECTION_BAD' ], and A SECOND call to PQfinish(..) make the client to crash with a system message 'segmentation fault'.

The source code I made to test interactively connections, disconnections and status is attached to this mail.

I could be told that one does not call PQfinish() when PQstatus is 'CONNECTION_BAD, but it is done in the PostgreSQL documentation example (Programmer's guide, chapter 1.11)

I hope this will be useful for you.

Here is my computer configuration :
    CPU    :    Pentium II 350 MHz
    OS        :    Linux  SuSE 7.2 upgraded with kernel 2.4.8
    Compiler :  GNU gcc version2.95.3
    Linker  :  GNU ld version 2.10.91 (with BFD 2.10.91.0.4)
PostgreSQL : Version 7.1.3 (downloaded on ftp.fr.postgresql.org )
 

-- 
Jean-Michel Chabanne
77450 MONTRY (FRANCE)
48" 54' N - 2" 49' E
Powered by Linux
 
#include <stdio.h>
#include "/usr/local/pgsql/include/libpq-fe.h"

PGconn *conn;
PGresult *res;

main(void)
{
int key;

char *pghost=NULL;
char *pgport=NULL;
char *pgoptions=NULL;
char *pgtty=NULL;
char *dbName="test";
char *user="jmc";
char *pwd;

        printf("Type one of the following actions, and press RETURN.\n");
        while(1)
        {
                (void)printf("Quit = Q  Connect+status = C"
                        "  Disconnect+status = D  Status_only = * : ");
                key = getchar();
                if(key == 10)
                        continue;
                switch(key)
                {
                        case 'c' :
                        case 'C' :
                        conn = PQsetdbLogin(pghost, pgport, pgoptions, \
                        pgtty, dbName, user, pwd);
                        break;

                        case 'd' :
                        case 'D' :
                        PQfinish(conn);
                        break;

                        case 'q' :
                        case 'Q' :
                        return 0;

                        default :
                        break;
                }

                switch(PQstatus(conn))
                {
                        case CONNECTION_OK :
                        (void)printf("\t---> OK\n");
                        break;
        
                        case CONNECTION_BAD :
                        (void)printf("\t---> BAD\n");
                        break;
        
                        case CONNECTION_STARTED :
                        (void)printf("\t---> STARTED\n");
                        break;
        
                        case CONNECTION_MADE :
                        (void)printf("\t---> MADE\n");
                        break;
        
                        case CONNECTION_AWAITING_RESPONSE :
                        (void)printf("\t---> AWAITING_RESPONSE\n");
                        break;
        
                        case CONNECTION_AUTH_OK :
                        (void)printf("\t---> AUTH_OK\n");
                        break;
        
                        case CONNECTION_SETENV :
                        (void)printf("\t---> SETENV\n");
                        break;
        
                        default :
                        printf("\t---> Default\n");
                }
        key = getchar();
        if(key != 10)
                ungetc(key, stdin);
        }
return 0;
}

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to