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

From madhtr
Subject Re: pqlib in c++: PQconnectStart PQconnectPoll
Date
Msg-id 000f01c750a9$a6ffb720$6401a8c0@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  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
----- 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 18:50
Subject: Re: [GENERAL] pqlib in c++: PQconnectStart PQconnectPoll


> "madhtr" <madhtr@schif.org> writes:
>> cleary I am going to have to study this documentation more carefully ...
>> So
>> ... for simplicity's sake, If I just do the following, how do I get back
>> "database does not exist" ?
>
> [ shrug... ]  Your program works perfectly for me:
>
> $ ./testit
> PQerrorMessage(lpcn) returns:
>
> FATAL:  database "nonexistantdb" does not exist
>
>
> PQstatus(lpcn)
> returns 1
> $
>
> ... although it takes a good long while (several seconds) because of the
> "sleep(1)" in the interaction with the postmaster.

hmm ... TY, must be my version or something like you state further down.

Sleep(1) should be only 1/1000 of a second. I do that so I don't hammer the
processor with my while loop when i am not  using a select().

>
> Maybe your problem is not with the program, but with the postmaster
> you're trying to connect to?  Does psql work?
>

yep, good thought. psql command line works fine, its sycnhronous tho.

>> source: http://www.postgresql.org/docs/7.3/static/libpq-connect.html
>
> Another line of thought, given the reading-between-the-lines conclusion
> that you are trying to use PG 7.3 libraries on Windows, is that there
> was something broken in the async-connect code back then on that
> platform.  If you really are trying to do that, do yourself a favor and
> move to 8.0 or later.  Nobody's going to be very interested in fixing
> 7.3.  (I did try your program with 7.3 on Unix, though, and it seemed
> fine except the error message was spelled a bit differently.)
>

Ty, I'll check that ... :)

>> I was also under the assumption that I would not need to perform my own
>> selects on the underlying socket, and that whatever I got back would be
>> either a null pointer, a successful connection pointer, or a broken
>> connection pointer with an error indication.
>
> You don't *have* to perform selects on the underlying socket, but if you
> are not multiplexing this activity with some other I/O, I have to wonder
> why you are bothering with an asynchronous connect at all.  What you've
> got at the moment is a poorly-implemented equivalent of PQconnectdb().

yep, the little simplified program is fairly pointless... but in RL, i will
pass a pointer to a cancel flag ...

void connect(bool* lpcancel){
    while (!*lpcancel && trying2connect){
        // yadda yadda yadda
    };
};

so that the user can click the "connect" button, start a thread, and then
click the "cancel" button instead giving my app the three finger salute if
they grow impatient, heh;)

In any case, I very much appreciate your help and time, I'll let you know
what I figure out. I bet you're right about the version.  Hopefully I can
contribute something back to the list at some point.  Again, sry for the
sloppy code at the beginning :)

madhtr



pgsql-general by date:

Previous
From: "Trevor Talbot"
Date:
Subject: Re: Moving to postgresql and some ignorant questions
Next
From: "Merlin Moncure"
Date:
Subject: Re: MVCC cons