Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

pqxx::CachedResult Class Reference

#include <cachedresult.h>

List of all members.

Public Types

typedef Result::size_type size_type
typedef size_type blocknum
typedef Result::Tuple Tuple
 Tuple type. Currently borrowed from Result, but may change in the future.


Public Member Functions

 CachedResult (pqxx::TransactionItf &T, const char Query[], const PGSTD::string &BaseName="query", size_type Granularity=100)
const Tuple operator[] (size_type i) const
 Access a tuple. Invalid index yields undefined behaviour.

const Tuple at (size_type i) const
 Access a tuple. Throws exception if index is out of range.

size_type size () const
 Number of rows in result set. First call may be slow.

bool empty () const
 Is the result set empty, i.e. does it contain no rows? May fetch 1 block.


Detailed Description

Cached result set. Chunks of result data are transparently fetched on-demand and stored in an internal cache for reuse. Functionality is similar to that of Result, with certain restrictions and different performance characteristics. A CachedResult must live in the context of a transaction, so that it can fetch further rows as they are needed.

The class uses a Cursor internally to fetch results. Data are not fetched row-by-row, but in chunks of configurable size. For internal computational reasons, these chunks (called "blocks" here) must be at least 2 rows large.

CAUTION: PostgreSQL currently doesn't always let you move cursors backwards, which is a feature this class relies upon. As a result, CachedResult will only work on certain types of queries. To make things worse, there is no documentation to define exactly which queries those are. Therefore the only way to use CachedResult at this time is to test carefully. Hopefully this can be fixed in the future.


Member Typedef Documentation

typedef size_type pqxx::CachedResult::blocknum
 

typedef Result::size_type pqxx::CachedResult::size_type
 

typedef Result::Tuple pqxx::CachedResult::Tuple
 

Tuple type. Currently borrowed from Result, but may change in the future.


Constructor & Destructor Documentation

pqxx::CachedResult::CachedResult pqxx::TransactionItf   T,
const char    Query[],
const PGSTD::string &    BaseName = "query",
size_type    Granularity = 100
[explicit]
 

Perform query and transparently fetch and cache resulting data.

Parameters:
T is the transaction context in which the CachedResult lives. This will be used whenever data is fetched.
Query is the SQL query that yields the desired result set.
BaseName gives the initial part of the name for this CachedResult and the Cursor it uses to obtain its results.
Granularity determines how large the blocks of data used internally will be; must be at least 2.


Member Function Documentation

const Tuple pqxx::CachedResult::at size_type    i const
 

Access a tuple. Throws exception if index is out of range.

If the given index is not the index of an existing row, an out_of_range error will be thrown.

Caveat: the Tuple contains a reference to a Result that may be destroyed by any other operation on the CachedResult, even if its constness is preserved. Therefore only use the returned Tuple as a temporary, and do not try to copy-construct it, or keep references or pointers to it.

Parameters:
i the number of the tuple to be accessed.

bool pqxx::CachedResult::empty   const
 

Is the result set empty, i.e. does it contain no rows? May fetch 1 block.

const Tuple pqxx::CachedResult::operator[] size_type    i const
 

Access a tuple. Invalid index yields undefined behaviour.

Caveat: the Tuple contains a reference to a Result that may be destroyed by any other operation on the CachedResult, even if its constness is preserved. Therefore only use the returned Tuple as a temporary, and do not try to copy-construct it, or keep references or pointers to it.

Parameters:
i the number of the tuple to be accessed.

pqxx::CachedResult::size_type pqxx::CachedResult::size   const
 

Number of rows in result set. First call may be slow.


The documentation for this class was generated from the following files:
Generated on Fri Feb 28 19:23:33 2003 for libpqxx by doxygen1.3-rc3