Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

RWDBReader



Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <rw/db/reader.h>

RWDBReader rdr = myTable.reader();
RWDBReader rdr = mySelector.reader();
RWDBReader rdr = myMemTable.reader();

Description

Class RWDBReader provides row-by-row access to tabular data. RWDBReaders are produced by RWDBTables. When instantiated, an RWDBReader is positioned before the first row of the table that produced it. Subsequently, it can repeatedly advance to the next row, but can never retreat. The contents of each row, however, may be accessed at random. The function operator () is used to advance an RWDBReader one row. Within a row, the operators for indexing [] and extraction >> may be used to access data.

The RWDBReader extraction operator >> is used to transfer data from the current row into program variables. DBTools.h++ has defined operator>> variants for all native C++ types, as well as for RWCString, RWDBDateTime, RWDecimalPortable (money), and RWDBBlob. Programmers are encouraged to define variants for classes in their application domain.

RWDBReader has a notion of the current position within the current row. Each time the reader is advanced to a new row, the position is set to 0. Each extraction increments the position by 1. The indexing operators [] set the position to a specified index, column, or column name; they return a reference to self, so that any of the following notations may be used:

RWDBReader is designed around the Interface/Implementation paradigm. An RWDBReader instance is an interface to a reference-counted implementation; copy constructors and assignment operators produce additional references to a shared implementation. An RWDBReader implementation is a base class from which a family of database-specific reader implementations is derived.

Example

In this example, assume that there is a database table Employees, with a unique integer key field id, text field name, and date field dateOfBirth. We define an employee class, along with an operator to extract an employee record from an RWDBReader, and include a constructor to retrieve an employee record given an id.

Related Classes

DBTools.h++ stores the data from the database in RWDBValues. See RWDBValue for information about conversions from RWDBValue to C++ types. For information about the conversion from database-specific datatypes to RWDBValue, see the DBTools.h++ access library guide for each database.

Applications that need to detect NULL values explicitly can use an RWDBNullIndicator to test whether or not the next data item to be extracted is NULL. Extracting into an RWDBNullIndicator sets the indicator to TRUE if the data item at the current row position is NULL, otherwise sets it to FALSE. The current row position is left unchanged.

Public Constructors

RWDBReader();
RWDBReader(const RWDBReader& reader);

Public Member Operators

RWDBReader& 
operator=(const RWDBReader& reader);
void*
operator()();

NOTE:In asynchronous mode, you must check the validity of the reader prior to shifting out values from the reader.
RWDBReader&
operator[](size_t index);
RWDBReader&
operator[](const RWCString& colName);
RWDBReader&
operator[](const RWDBColumn& column);
RWDBReader& 
operator>>(char& value); 
RWDBReader& 
operator>>(unsigned char& value); 
RWDBReader& 
operator>>(short& value); 
RWDBReader& 
operator>>(unsigned short& value); 
RWDBReader& 
operator>>(int& value); 
RWDBReader& 
operator>>(unsigned int& value); 
RWDBReader& 
operator>>(long& value); 
RWDBReader& 
operator>>(unsigned long& value); 
RWDBReader& 
operator>>(float& value); 
RWDBReader& 
operator>>(double& value); 
RWDBReader& 
operator>>(RWDecimalPortable& value); 
RWDBReader& 
operator>>(RWDate& value); 
RWDBReader& 
operator>>(RWTime& value); 
RWDBReader& 
operator>>(RWDBDateTime& value); 
RWDBReader& 
operator>>(RWDBDuration& value); 
RWDBReader& 
operator>>(RWCString& value); 
RWDBReader& 
operator>>(RWDBBlob& value); 
RWDBReader& 
operator>>(RWDBMBString& value);
RWDBReader& 
operator>>(RWWString& value);
RWDBReader&
operator>>(RWDBNullIndicator& nullIndictator);
RWDBReader&
operator>>(RWDBValue& value);
RWDBReader&
operator>>(RWDBRow& row);

Public Member Functions

void
acquire() const;
RWDBConnection 
connection() const;
RWDBStatus::ErrorHandler
errorHandler() const;
RWBoolean
isReady();
RWBoolean
isValid() const;
void
release() const;
void 
setErrorHandler(RWDBStatus::errorHandler errorHandler);
RWDBStatus
status() const;
RWDBTable
table() table const;

Related Global Operator

RWDBInserter&
operator<<(RWDBReader& rdr);


Previous fileTop of DocumentContentsIndexNext file

©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.