Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
DB Interface Module Reference Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

RWDBReader

Module:  DB Interface Module   Group:  Data Manipulation Classes


Does not inherit

Local Index

Members

Non-Members

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. The DB Interface Module has defined operator>> variants for all native C++ types, as well as for RWCString, RWDateTime, RWDBDateTime, RWDecimalPortable, 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

The DB Interface Module stores the data from the database in RWDBValues. See RWDBValue for information about conversions from table to C++ types. For information about the conversion from database-specific data types to RWDBValue, see the DB Access Module 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>>(long long& value); 
RWDBReader& 
operator>>(unsigned long long& value); 
RWDBReader& 
operator>>(float& value); 
RWDBReader& 
operator>>(double& value);
RWDBReader& 
operator>>(long double& value);
RWDBReader& 
operator>>(RWDecimalPortable& value); 
RWDBReader& 
operator>>(RWDate& value); 
RWDBReader& 
operator>>(RWTime& value);
RWDBReader&
operator>>(RWDateTime& 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>>(RWBasicUString& value); 

NOTE -- This function accepts Unicode strings. For more information, see the entry for RWBasicUString in the Essential Tools Module Reference Guide. For more information on internationalization, see Chapter 13 of the DB Interface Module User's Guide.
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;
bool
isReady();
bool
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 DocumentContentsIndex pageNext file

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