Previous: pg_stream Table of contents Next: pg_stmt

The pg_cursor class

This class inherits pg_stream and is to be used for fetching large result sets in chunks. It encapsulates the instantiation and use of a SQL cursor object.
By using a cursor, the first results are available faster, and the memory requirements are lowered since only a chunk of results has to be present in memory at a time.
Note that this class doesn't allow to move the cursor backward within the results, nor to fast forward.

Public functions

Initialization

pg_cursor (unsigned int step, const char* query, pg_cnx& db)
Constructor. Creates a pg_cursor object to execute the SQL query through the db connexion. query is a SQL sentence that can contains parameters, whose syntax and use is identical to those of a pg_stream object.
step is the maximum number of rows that will be fetched at each server round-trip.
pg_cursor (unsigned int step, std::string query, pg_cnx& db)
This is the same as the previous constructor except for the usage of the std::string type for query. It is provided for convenience.
[virtual] ~pg_cursor ()
Destructor. Deallocates the cursor and other resources used by the object.

Passing parameters and getting results work exactly like for a pg_stream object. SQL FETCH commands are internally issued by the library when a new chunk of results is needed.

Implementation notes

  1. Cursors implicitly instantiated by the pg_cursor class are named pgst_cur_ followed by an hex number. Thus such names should be considered as reserved by the pgstream library, and not used by the application code.


Previous: pg_stream Table of contents Next: pg_stmt