Re: I have a C to postgres question.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jay G(dot) Scott" <gl(at)arlut(dot)utexas(dot)edu>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: I have a C to postgres question.
Date: 2003-01-30 17:02:22
Message-ID: 20158.1043946142@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Jay G. Scott" <gl(at)arlut(dot)utexas(dot)edu> writes:
> igot = PQsendQuery(conn_to_db,select_stmt);
> fprintf(stderr,"igot from query is %d\n", igot );
> seek_m_id = PQgetResult(conn_to_db); <<<<<<<<<<<<<<<<<<<<<<<<

> estgot = PQresultStatus( seek_m_id );

> fprintf(stderr,"estgot from PQgetResult is %d\n", estgot );

> while( seek_m_id != NULL )
> {
> fprintf(stderr,"seek_m_id != NULL\n");
> seek_m_id = PQgetResult(conn_to_db); <<<<<<<<<<<<<<<<<<<<<<<<
> estgot = PQresultStatus( seek_m_id );
> tmwh( estgot );
> /* i suppose nrows could keep coming back as 1 */
> nrows = PQntuples( seek_m_id );

You did too many PQgetResult's. I'd suggest coding like

while ((seek_m_id = PQgetResult(conn_to_db)) != NULL)
{
... process seek_m_id ...
PQclear(seek_m_id);
}

so that there's only one PQgetResult call.

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Rosta Farzan 2003-01-30 17:08:30 Re: Perl - Postgres
Previous Message pginfo 2003-01-30 16:37:27 Re: Sun J2EE server (default with J2EE package) + PostgreSQL jdbc