Re: pqlib in c++: PQconnectStart PQconnectPoll - Mailing list pgsql-general

From madhtr
Subject Re: pqlib in c++: PQconnectStart PQconnectPoll
Date
Msg-id 001401c7507c$b7d62520$7b55503f@useronewin2klt
Whole thread Raw
In response to Moving to postgresql and some ignorant questions  ("Phoenix Kiula" <phoenix.kiula@gmail.com>)
Responses Re: pqlib in c++: PQconnectStart PQconnectPoll
List pgsql-general
ok thanx:)

 ... here's the source ... can u tell me whats wrong? (the purpose of this
function is to allow for thread safety on the connection, and allow for
cancellation if the connection takes too long)

BTW ...

- coninfo is "host=localhost port=5432 dbname=testdb user=localuser
password=localpassword"
- I am using VC++ and compiling a windows execuatble ...

PGconn* PQconnectStartCS(const char* coninfo,LPCRITICAL_SECTION lpcs,bool*
lpcancel,int* lppge){
    int& pge = *lppge;
    bool& cancel = *lpcancel;
    bool keepon = true;
    PGconn* pr = 0;
    pge = 0;
    EnterCriticalSection(lpcs);
    pr = PQconnectStart(coninfo);

    while (!killthread(&cancel) && keepon){
        switch(pge = PQconnectPoll(pr)){
        case PGRES_POLLING_FAILED:
            keepon = false;
            break;
        case PGRES_POLLING_OK:
            pge = 0;
            keepon = false;
            break;
        default:
            break;
        };
        if (keepon)
            Sleep(1);
    };

    LeaveCriticalSection(lpcs);
    if (!pge && pr){
        switch(pge = PQstatus(pr)){
        case CONNECTION_OK:
            pge = 0;
            break;
        };
    };
    return pr;
};

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "madhtr" <madhtr@schif.org>
Cc: <pgsql-general@postgresql.org>
Sent: Tuesday, August 14, 2007 14:36
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll


> "madhtr" <madhtr@schif.org> writes:
>> when i intentioally try to connect asynchronously to a database that does
>> not exist, i get
>
>> "server closed the connection unexpectedly"
>
> There's something wrong with your code then.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "madhtr" <madhtr@schif.org>
Cc: <pgsql-general@postgresql.org>
Sent: Tuesday, August 14, 2007 14:36
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll


> "madhtr" <madhtr@schif.org> writes:
>> when i intentioally try to connect asynchronously to a database that does
>> not exist, i get
>
>> "server closed the connection unexpectedly"
>
> There's something wrong with your code then.
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings



pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Select time jump after adding filter; please help me figure out what I'm doing wrong.
Next
From: Kirk Wythers
Date:
Subject: query help