pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to use PQconsumeInput and PQisBusy correctly ?
2+ messages / 2 participants
[nested] [flat]
* How to use PQconsumeInput and PQisBusy correctly ?
@ 2005-03-13 15:56 Rodrigo Moreno <rodrigo.miguel@terra.com.br>
0 siblings, 1 reply; 2+ messages in thread
From: Rodrigo Moreno @ 2005-03-13 15:56 UTC (permalink / raw)
To: pgsql-interfaces
Hi all,
What's the right way to use pqconsumeinput and pqisbusy ?
The below code could be used to do that ?
Thanks a Lot
Rodrigo Moreno
PS: Please don't worry if some code is wrong, I do not test this code yeat.
void query(PGconn *conn, const char *stmt)
{
PGresult *res;
int nFields;
int i,j;
int send;
send = PQsendQuery(conn, stmt);
if (PQconsumeInput(conn))
{
while (PQisBusy(conn))
{
printf(".");
sleep(500);
PQconsumeInput(conn);
}
res = PQgetResult(conn);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
{
fprintf(stderr, "failed: %s", PQerrorMessage(conn));
PQclear(res);
exit_nicely(conn);
}
nFields = PQnfields(res);
for (i = 0; i < nFields; i++)
printf("%-15s", PQfname(res, i));
printf("\n\n");
for (i = 0; i < PQntuples(res); i++)
{
for (j = 0; j < nFields; j++)
printf("%-15s", PQgetvalue(res, i, j));
printf("\n");
}
PQclear(res);
}
}
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: How to use PQconsumeInput and PQisBusy correctly ?
@ 2005-03-13 18:54 Tom Lane <tgl@sss.pgh.pa.us>
parent: Rodrigo Moreno <rodrigo.miguel@terra.com.br>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2005-03-13 18:54 UTC (permalink / raw)
To: Rodrigo Moreno <rodrigo.miguel@terra.com.br>; +Cc: pgsql-interfaces
"Rodrigo Moreno" <rodrigo.miguel@terra.com.br> writes:
> What's the right way to use pqconsumeinput and pqisbusy ?
> The below code could be used to do that ?
It would work but it seems rather pointless; the only reason you would
use those functions is if you have something else useful to do while
waiting for the query result ... and this program structure isn't
very conducive to doing other stuff while waiting. Usually you'd want
to have a main loop that can dispatch handling of various events, one
of them being checking for an available query result.
The whole thing is a bit of a stone-age technique anyway; if you were
thinking of starting a new program today you'd probably use threads in
preference to an event loop.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-03-13 18:54 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-03-13 15:56 How to use PQconsumeInput and PQisBusy correctly ? Rodrigo Moreno <rodrigo.miguel@terra.com.br>
2005-03-13 18:54 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox