SourcePro® API Reference Guide

 
List of all members | Public Member Functions
RWDBBulkInserter Class Reference

Used to insert an RWDBTBuffer array into a database table. (To insert scalar values, use RWDBInserter.) More...

#include <rw/db/bkins.h>

Public Member Functions

 RWDBBulkInserter ()
 
 RWDBBulkInserter (const RWDBBulkInserter &ins)
 
RWDBResult execute ()
 
RWDBResult execute (size_t iters)
 
bool isValid () const
 
RWDBBulkInserteroperator<< (const RWDBAbstractBuffer &val)
 
RWDBBulkInserteroperator<< (const RWDBDateVector &dateVector)
 
RWDBBulkInserteroperator= (const RWDBBulkInserter &ins)
 
RWDBBulkInserteroperator[] (size_t index)
 
RWDBBulkInserteroperator[] (const RWCString &columnName)
 
RWDBBulkInserteroperator[] (const RWDBColumn &column)
 
size_t position () const
 
RWDBStatus status () const
 

Detailed Description

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 class RWDBTBuffer is used for inserting all types of data, including numeric types, dates, strings and binary data.

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.

Synopsis
#include <rw/db/bkins.h>
#include <rw/db/table.h>
RWDBBulkInserter ins = table.bulkInserter(connection);
Example

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.
const int length = 10;
RWDBTBuffer< RWCString > stringBuffer(length);
RWDBTBuffer< int > intBuffer(length);
// Populate the arrays using a user-defined function.
setValues(stringBuffer, intBuffer);
// Define the inserter.
RWDBBulkInserter ins = tab.bulkInserter(connection);
// Shift the arrays into the inserter.
ins << stringBuffer << intBuffer;
// Insert up to length values at a time.
RWDBResult result = ins.execute(length);

Constructor & Destructor Documentation

RWDBBulkInserter::RWDBBulkInserter ( )

Default constructor. Creates an RWDBBulkInserter whose status is RWDBStatus::notInitialized. This constructor is provided as a convenience; for example, to declare an array of RWDBBulkInserter instances. Usable RWDBBulkInserter objects are obtained from valid RWDBTable objects.

RWDBBulkInserter::RWDBBulkInserter ( const RWDBBulkInserter ins)

Copy constructor. The created RWDBBulkInserter shares an implementation with ins.

Member Function Documentation

RWDBResult RWDBBulkInserter::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 RWDBBulkInserter::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.

bool RWDBBulkInserter::isValid ( ) const

Returns true if self's status is RWDBStatus::ok, otherwise returns false.

RWDBBulkInserter& RWDBBulkInserter::operator<< ( const 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.

RWDBBulkInserter& RWDBBulkInserter::operator<< ( const RWDBDateVector dateVector)
Deprecated:
As of SourcePro 6, use RWDBBulkInserter::operator<<(const 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.

RWDBBulkInserter& RWDBBulkInserter::operator= ( const RWDBBulkInserter ins)

Assignment operator. Self shares an implementation with ins.

RWDBBulkInserter& RWDBBulkInserter::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.

RWDBBulkInserter& RWDBBulkInserter::operator[] ( const RWCString columnName)

Changes the current column position to columnName and sets the column list.

RWDBBulkInserter& RWDBBulkInserter::operator[] ( const RWDBColumn column)

Changes the current column position to column and sets the column list.

size_t RWDBBulkInserter::position ( ) const

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

RWDBStatus RWDBBulkInserter::status ( ) const

Returns the status of self.

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