Обсуждение: Reset the cursor to start from the record 1

Поиск
Список
Период
Сортировка

Reset the cursor to start from the record 1

От
Igor Korot
Дата:
 Hi, ALL,
I'd like to do the following:

[code]
PGresult res = PQprepare();
if( PQresultStatus( res ) != PGRES_COMMAND_OK )
{
// error handling
}
else
{
    PGresult res1 = PQexecPrepared();
    status = PQresultStatus( res1 );
    if( status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK )
    {
// error handling
    }
    else if( status == PGRES_TUPLES_OK )
    {
        for( int j = 0; j < PQntuples( res1 ); j++ )
        {
// process the recordset
        }
        for( int j = 0; j < PQntuples( res1); j++ )
        {
// process the same recordset again
        }
    }
}
[/code]

Is there a function which just reset the record pointer to 1, so I can reprocess
those records?

Thank you.


Re: Reset the cursor to start from the record 1

От
"David G. Johnston"
Дата:
On Tue, Jun 5, 2018 at 2:08 PM, Igor Korot <ikorot01@gmail.com> wrote:
Is there a function which just reset the record pointer to 1, so I can reprocess
those records
​?

​While I haven't actually programmed using this API...

The documentation doesn't seem to indicate the presence of a "record pointer", it shows that PQgetvalue accepts both row and column numbers as input, and it indicates the PGResult stays in memory - and contains the entire result - until PQclear'ed.  This leads me to think that you should be able to access values in any cell at any time, including multiple times, without issue.  Have you tried it?

Now, if you are using Row-by-Row mode that likely varies a bit: but your example doesn't show that to be the case.

​David J.