SourcePro® API Reference Guide

 
List of all members | Public Member Functions
RWDBBulkReader Class Reference

Reads result sets, represented as arrays of RWDBTBuffer 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)
 
int cancel ()
 
bool isValid () const
 
size_t operator() ()
 
RWDBBulkReaderoperator<< (RWDBAbstractBuffer &val)
 
RWDBBulkReaderoperator<< (RWDBDateVector &dateVector)
 
RWDBBulkReaderoperator= (const RWDBBulkReader &rdr)
 
RWDBBulkReaderoperator[] (size_t index)
 
size_t position () const
 
RWDBStatus status () const
 

Detailed Description

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 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.

Synopsis
#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);
Example

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< 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] );
}

Constructor & Destructor Documentation

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.

Member Function Documentation

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<< ( 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.

RWDBBulkReader& RWDBBulkReader::operator<< ( RWDBDateVector dateVector)
Deprecated:
As of SourcePro 6, use RWDBBulkReader::operator<<(RWDBAbstractBuffer&), passing in RWDBTBuffer<RWDateTime> instead.

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= ( const RWDBBulkReader rdr)

Assignment operator. Self shares an implementation with rdr.

RWDBBulkReader& RWDBBulkReader::operator[] ( size_t  index)

Changes the current column position to index. If index is out of range, self's status is set to RWDBStatus::invalidPosition. Returns a reference to self.

size_t RWDBBulkReader::position ( ) const

Returns the current column position, at which the next buffer will be shifted in using the extraction operator. Returns RW_NPOS if isValid() returns false.

RWDBStatus RWDBBulkReader::status ( ) const

Returns the status of self.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.