Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

RWDBInserter



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

Synopsis

#include <rw/db/inserter.h>

RWDBInserter inserter = myTable.inserter();
RWDBInserter inserter = myTable.inserter(mySelector);

Description

RWDBInserter is an encapsulation of the SQL INSERT statement. In SQL, the INSERT statement may be based either on a VALUES clause or on a SELECT statement. RWDBInserter supports either variant. Use the insertion operator << to add items to an RWDBInserter encapsulated VALUES clause, or supply an RWDBSelector when the RWDBInserter is produced. It is an error to use the insertion operator << with an RWDBInserter that was produced with an RWDBSelector.

An RWDBInserter can be produced with an optional RWDBSchema, which is used to generate a list of column names. If the list of column names is given, the values are inserted one for one into the specified columns. Otherwise the values are inserted into the table columns in the order they were created.

RWDBInserters that use the indexing operator, operator[], with colName derive a list of column names if all columns are provided. This allows values to be shifted into the inserter in any order, without requiring a schema and an additional database access.

RWDBInserter has a notion of the current position in itself. This position is set to zero when the RWDBInserter is produced, and reset to zero whenever execute() is called. Each insertion operation adds a value at the current position and increments the position by one. If the RWDBInserter was created with an optional RWDBSchema, then the indexing operators [] can set the position to a specified column or column name, and return a reference to self. DBTools.h++ does not check to see if the inserted values match the table's schema in type or in number; such errors are reported by the database when execute() is invoked.

An INSERT statement does not normally produce results. However, DBTools.h++ recognizes that some database vendors provide triggers, which can cause results to be generated by an INSERT statement. Consequently, the RWDBInserter execute() method returns an RWDBResult, which is a sequence of zero or more RWDBTables. Applications are not obliged to request any tables from the returned object.

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

Example 1

For this example, assume an AutoParts table in the database, with text column name and integer column id. Here is a way to populate it with data selected from another table, AllParts, which is also assumed to have a name and an id column.

Example 2

This is how to insert a single row, using an encapsulated VALUES clause:

Example 3

This is how to insert a single row, using a column list and an encapsulated VALUES clause. The correct order of insertions depends on the supplied RWDBSchema, not on the order of columns in the autoParts table:

Example 4

This is how to insert a single row, using a column list, but supplying bindings to application variables. The advantage here is that the same insertion can be made several times without reshifting variables:

Related Objects

RWDBValueManip rwdbNull;

Public Constructors

RWDBInserter();
RWDBInserter(const RWDBInserter& ins);

Public Member Operators

RWDBInserter &
operator[](const RWCString& colName);
RWDBInserter &
operator[](const RWDBColumn& column);
RWDBInserter&
operator=(const RWDBInserter& ins);
RWDBInserter&       
operator<<(const RWDBValue& value);
RWDBInserter&       
operator<<(char value);
RWDBInserter&       
operator<<(unsigned char value);
RWDBInserter&       
operator<<(short value);
RWDBInserter&       
operator<<(unsigned short value);
RWDBInserter&       
operator<<(int value);
RWDBInserter&       
operator<<(unsigned int value);
RWDBInserter&       
operator<<(long value);
RWDBInserter&       
operator<<(unsigned long value);
RWDBInserter&       
operator<<(float value);
RWDBInserter&       
operator<<(double value);
RWDBInserter&       
operator<<(const char* value);
RWDBInserter&       
operator<<(const RWDecimalPortable& value);
RWDBInserter&       
operator<<(const RWDate& value);
RWDBInserter&       
operator<<(const RWDBDateTime& value);
RWDBInserter&       
operator<<(const RWDBDuration& value);
RWDBInserter&       
operator<<(const RWCString& value);
RWDBInserter&       
operator<<(const RWDBMBString& value);
RWDBInserter&       
operator<<(const RWWString& value);
RWDBInserter&       
operator<<(const RWDBBlob& value);
RWDBInserter&
operator<<(const RWDBExpr& value);
RWDBInserter&
operator<<(const RWDBBoundExpr& value);
RWDBInserter&
operator<<(RWDBReader& reader);
RWDBInserter& 
operator<<(RWDBValueManip& manip);

Public Member Functions

void
acquire() const;
RWDBInserter&
addValue(const RWDBExpr& value);
RWDBInserter&
addValue(const RWDBBoundExpr& value);
RWCString
asString() const;
RWDBStatus
clear();
RWDBStatus::ErrorHandler
errorHandler() const;
RWDBResult
execute();
RWDBResult
execute(const RWDBConnection& connection);
RWDBResult
flush();
RWBoolean
isReady() const;
RWBoolean
isValid() const;
void
release() const;
void
setErrorHandler(RWDBStatus::ErrorHandler handler);
RWDBStatus
status() const;
RWDBTable
table() const;


Previous fileTop of DocumentContentsIndexNext file

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