Search Postgresql Archives

Re: pqlib in c++: PQconnectStart PQconnectPoll

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




----- Original Message ----- From: "Tom Lane" <tgl@xxxxxxxxxxxxx>
To: "madhtr" <madhtr@xxxxxxxxx>
Cc: <pgsql-general@xxxxxxxxxxxxxx>
Sent: Tuesday, August 14, 2007 18:50
Subject: Re:  pqlib in c++: PQconnectStart PQconnectPoll


"madhtr" <madhtr@xxxxxxxxx> 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


---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

              http://archives.postgresql.org/

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux