Member Functions | |||
execute() isValid() |
operator<<() operator=() |
operator[]() status() |
#include <rw/db/bkins.h> #include <rw/db/table.h> RWDBBulkInserter ins = table.bulkInserter(connection);
Like RWDBInserter, RWDBBulkInserter is a class designed to insert data into database tables. The main difference between RWDBBulkInserter and RWDBInserter is that arrays of values are shifted into RWDBBulkInserter for each column in the table, while scalar values are shifted into RWDBInserter. These arrays are passed by reference and need to stay in scope for the duration of the inserter. The classes RWDBVector<T>, RWDBDateVector, RWDBStringVector, and RWDBBinaryVector are used for inserting simple numeric types, dates, strings, and binary data respectively.
RWDBBulkInserter is designed around the Interface/Implementation paradigm. An RWDBBulkInserter instance is an interface to a reference-counted implementation; copy constructors and assignment operators produce additional references to a shared implementation. An RWDBBulkInserter implementation is a base class from which a family of database-specific implementations is derived.
The following example uses an RWDBBulkInserter to insert an array of strings and integers into a table.
// Define the arrays that will hold the data to be // inserted. int width = 80; int length = 10; RWDBStringVector stringVector(width, length); RWDBVector< int > intVector(length); // Populate the arrays using a user-defined function. setValues(stringVector, intVector); // Define the inserter. RWDBBulkInserter ins = tab.bulkInserter(connection); // Shift the arrays into the inserter. ins << stringVector << intVector; // Insert up to length values at a time. RWDBResult result = ins.execute(length);
RWDBBulkInserter();
Default constructor. Creates an RWDBBulkInserter whose status is RWDBStatus::notInitialized. This constructor is provided as a convenience; for example, for declaring an array of RWDBBulkInserters. Usable RWDBBulkInserters are obtained from valid RWDBTables.
RWDBBulkInserter(const RWDBBulkInserter& ins);
Copy constructor. The created RWDBBulkInserter shares an implementation with ins.
RWDBBulkInserter& operator=(const RWDBBulkInserter& ins);
Assignment operator. Self shares an implementation with ins.
RWDBBulkInserter& 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.
RWDBBulkInserter& operator[](const RWCString& columnName);
Changes the current row position to columnName and sets the column list.
RWDBBulkInserter& operator[](const RWDBColumn& column);
Changes the current row position to column and sets the column list.
RWDBBulkInserter& 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.
Before DBTools.h++ 4.0, this operator<< took RWDBVector, which is now a derived class of RWDBAbstractBuffer. Code written with RWDBVector should require no changes.
RWDBBulkInserter& 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.
RWDBResult execute();
Causes each of the values associated with each of the arrays shifted into self to be inserted into the table associated with self. Returns an RWDBResult.
RWDBResult execute(size_t iters);
Causes the first iters values associated with each of the arrays shifted into self to be inserted into the table associated with self. Returns an RWDBResult.
RWBoolean isValid() const;
Returns TRUE is self's status is RWDBStatus::ok, otherwise returns FALSE.
RWDBStatus status() const;
Returns the status of self.
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.