Re: I have a C to postgres question.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: I have a C to postgres question.
Дата
Msg-id 20158.1043946142@sss.pgh.pa.us
обсуждение исходный текст
Ответ на I have a C to postgres question.  ("Jay G. Scott" <gl@arlut.utexas.edu>)
Список pgsql-novice
"Jay G. Scott" <gl@arlut.utexas.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

В списке pgsql-novice по дате отправления:

Предыдущее
От: Andres Ledesma
Дата:
Сообщение: postmaster don't start ...
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: Good books?