Search Postgresql Archives

Re: libpq sendQuery -- getResult not returning until all queries complete

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

 



This should do it:

#include <stdio.h>
#include <stdlib.h>
#include <libpq-fe.h>

#define CONNINFO "your info here"
#define COMMANDS "select current_timestamp; select pg_sleep(5); select
current_timestamp"

void fatal( const char *msg ) { fprintf( stderr, "%s\n", msg ); exit(1); }

int
main()
{
    PGresult *res = 0;
    PGconn *conn = PQconnectdb( CONNINFO );
    if (!conn) fatal("PQconnectdb returned null");

    if ( PQstatus(conn) != CONNECTION_OK ) {
        PQfinish( conn );
        fatal("PQconnectdb failed");
    }

    if (!PQsendQuery(conn, COMMANDS)) {
        PQfinish( conn );
        fatal("PQsendQuery failed");
    }

    while( (res = PQgetResult( conn )) != 0 ) {
        printf("retrieved result\n");
        PQclear(res);
    }

    PQfinish( conn );
    return 0;
}



On Tue, Dec 21, 2010 at 1:26 PM, Merlin Moncure <mmoncure@xxxxxxxxx> wrote:
> On Tue, Dec 21, 2010 at 2:21 PM, Peter Geoghegan
> <peter.geoghegan86@xxxxxxxxx> wrote:
>> You can't concurrently execute queries from within a single
>> connection. Perhaps you should use multiple connections, while
>> understanding the implications of having each operate within a
>> separate snapshot.
>
> OP is not suggesting that queries run concurrently, but asking why
> result sets can't be popped off as the queries resolve.  It's a good
> question; it's probably either a bug in the database or the
> documentation (if it does not turn out to be operator error).
>
> Kelly, if you can produce small test case in C I'll double check it.
>
> merlin
>

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[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