Skip site navigation (1) Skip section navigation (2)

How to use PQconsumeInput and PQisBusy correctly ?

From: "Rodrigo Moreno" <rodrigo(dot)miguel(at)terra(dot)com(dot)br>
To: <pgsql-interfaces(at)postgresql(dot)org>
Subject: How to use PQconsumeInput and PQisBusy correctly ?
Date: 2005-03-13 15:56:32
Message-ID: 20050313155643.687B23C00B@talara.terra.com.br (view raw or flat)
Thread:
Lists: 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);
    }        
}



Responses

pgsql-interfaces by date

Next:From: Tom LaneDate: 2005-03-13 18:54:14
Subject: Re: How to use PQconsumeInput and PQisBusy correctly ?
Previous:From: Peter MuchDate: 2005-03-13 15:05:04
Subject: Upd: [Tcl] did pgaccess ever work with kerberos?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group