SourcePro C++ 12.0 |
SourcePro® C++ API Reference Guide |
SourcePro C++ Documentation Home |
Reads result sets, represented as arrays of RWDBTBuffer<T> or RWDBDateVector, that are associated with an RWDBTable or RWDBSelector. (For reading scalar values, use RWDBReader.). More...
#include <rw/db/bkread.h>
Public Member Functions | |
RWDBBulkReader () | |
RWDBBulkReader (const RWDBBulkReader &rdr) | |
RWDBBulkReader & | operator= (const RWDBBulkReader &rdr) |
RWDBBulkReader & | operator[] (size_t index) |
RWDBBulkReader & | operator<< (RWDBAbstractBuffer &val) |
RWDBBulkReader & | operator<< (RWDBDateVector &dateVector) |
size_t | operator() () |
int | cancel () |
bool | isValid () const |
RWDBStatus | status () const |
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 class RWDBTBuffer<T> is used for reading all types of data, including numbers, dates, strings, and binary data.
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.
#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);
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. RWDBTBuffer< RWDateTime > dateBuffer(n); RWDBTBuffer< int > intBuffer(n); // Define the reader. RWDBBulkReader rdr = selector.bulkReader(connection); // Shift the arrays into the reader. rdr << dateBuffer << intBuffer; // Read up to n values at a time. int numRead; while ( numRead = rdr( ) ) { for (int i = 0; i < numRead ; i++) process( dateBuffer[i], intBuffer[i] ); }
RWDBBulkReader::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 RWDBBulkReader instances. Usable RWDBBulkReader objects are obtained from valid RWDBTable objects.
RWDBBulkReader::RWDBBulkReader | ( | const RWDBBulkReader & | rdr | ) |
Copy constructor. The created RWDBBulkReader shares an implementation with rdr.
int RWDBBulkReader::cancel | ( | ) |
Cancels any pending results associated with self. Subsequent calls to 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.
bool RWDBBulkReader::isValid | ( | ) | const |
Returns true
if self's status is RWDBStatus::ok, otherwise false
.
size_t RWDBBulkReader::operator() | ( | ) |
Fetches into the internal array 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 being fetched. Returns the number of rows actually fetched. A return value of 0
indicates that there is no additional data to fetch.
RWDBBulkReader& 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.
RWDBBulkReader& 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.
This operator is capable of taking RWDBTBuffer<T>.
RWDBBulkReader& RWDBBulkReader::operator= | ( | const RWDBBulkReader & | rdr | ) |
Assignment operator. Self shares an implementation with rdr.
RWDBBulkReader& 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.
RWDBStatus RWDBBulkReader::status | ( | ) | const |
Returns the status of self.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.