Member Functions | |||
cancel() isValid() |
operator<<() operator()() |
operator=() operator[]() |
status() |
#include <rw/db/bkread.h> #include <rw/db/select.h> #include <rw/db/table.h> RWDBBulkReader reader1 = table.bulkReader(connection); RWDBBulkReader reader2 = selector.bulkReader(connection);
Like RWDBReader, RWDBBulkReader is a class designed to read result sets associated with an RWDBTable or RWDBSelector. The main difference between RWDBBulkReader and RWDBReader is that arrays of values are shifted into the RWDBBulkReader for each column in the result set, while scalar values are shifted out of the RWDBReader. These arrays are passed by reference and need to stay in scope for the duration of the reader. The classes RWDBVector<T>, RWDBDateVector, RWDBStringVector, and RWDBBinaryVector are used for reading simple numeric types, dates, strings, and binary data, respectively.
RWDBBulkReader is designed around the Interface/Implementation paradigm. An RWDBBulkReader instance is an interface to a reference-counted implementation; copy constructors and assignment operators produce additional references to a shared implementation. An RWDBBulkReader implementation is a base class from which a family of database-specific implementations is derived.
The following example uses an RWDBBulkReader to read a result set, where the first column is a date and the second column is an integer.
// Set up the selector. RWDBSelector selector = db.selector(); selector << tab["datecolumn"] << tab["intColumn"]; // Define the arrays into which the data will be read. RWDBDateVector dateVector = db.dateVector(n); RWDBVector< int > intVector(n); // Define the reader. RWDBBulkReader rdr = selector.bulkReader(connection); // Shift the arrays into the reader. rdr << dateVector << intVector; // Read up to n values at a time. int numRead; while ( numRead = rdr( ) ) { for (int i = 0; i < numRead ; i++) process( dateVector[i], intVector[i] ); }
RWDBBulkReader();
Default constructor. Creates an RWDBBulkReader whose status is RWDBStatus::notInitialized. This constructor is provided as a convenience; for example, for declaring an array of RWDBBulkReaders. Usable RWDBBulkReaders are obtained from valid RWDBTables.
RWDBBulkReader(const RWDBBulkReader& rdr);
Copy constructor. The created RWDBBulkReader shares an implementation with rdr.
RWDBBulkReader& operator=(const RWDBBulkReader& rdr);
Assignment operator. Self shares an implementation with rdr.
RWDBBulkReader& operator[](size_t index);
Changes the current row position to index. If index is out of range, self's status is set to RWDBStatus::invalidPosition. Returns a reference to self.
RWDBBulkReader & operator<<(RWDBAbstractBuffer& val);
Shifts in the val to be associated with the column at the current position. Increments the current position. Returns a reference to self.
Before DBTools.h++ 4.0, this operator<< took RWDBVector, which is now a derived class of RWDBAbstractBuffer. Code written with RWDBVector should require no changes.
RWDBBulkReader & operator<<(RWDBDateVector& dateVector);
Shifts in the dateVector to be associated with the column at the current position. Increments the current position. Returns a reference to self.
size_t operator()();
Fetches into the arrays shifted into self, the next set of rows from the result set associated with self. Up to n rows are fetched at a time, where n is equal to the length of the shortest array shifted into shelf. Returns the number of rows actually fetched. A return value of 0 indicates that there is no additional data to fetch.
int cancel();
Cancels any pending results associated with self. Subsequent calls to RWDBBulkReader::operator()() iterate over a fresh result set based on the current values of the set of bound variables associated with the selector that produced self.
RWBoolean isValid() const;
Returns TRUE if self's status is RWDBStatus::ok, otherwise returns FALSE.
RWDBStatus status() const;
Returns the status of self.
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.