Product Documentation

c-treeDB API for C++ - Developers Guide

Previous Topic

Next Topic

CTRecord::InsertBatch

Inserts a new record into a batch buffer.

Declaration

void CTRecord::InsertBatch();

Description

Inserts a new record into a batch buffer maintained internally by c-treeDB. When the batch buffer fills up, the group of records stored in the batch buffer are inserted into the table. If CTRecord::EndBatch() is called and the batch buffer still contains records, a new insert record operation is performed for the remaining records before the batch operation is terminated.

For transaction controlled files, the batch insertion operation is treated as one all or nothing operation. If no explicit transaction is started, each insertion of records with will start and end its own transaction. Even if an explicit transaction is started, each insertion operation is treated independently through safe points.

Note: currently, all record insertion operations will not perform any conversion of record images, key values and record position for heterogeneous client/server implementations.

The following steps must be taken to perform a batch insert record operation:

  1. Call CTRecord::SetBatch() function, with CTBATCH_INS mode, to insert a group of records.

    For each record to be inserted perform the following operations:

    1. Call CTRecord::Clear() to clear a record buffer
    2. For each field in the record call one of the CTRecord::SetFieldAs...() functions to set the field data.
    3. Call CTRecord::InsertBatch() to insert the record into the batch buffer.
  2. Call CTRecord::EndBatch() to indicate that no more records will be inserted.

In case of errors, CTRecord::InsertBatch() throws a CTException.

Return

void

Example


try

{

// set the batch operation

hRecord.SetBatch(CTBATCH_INS, 0, 0);

// prepare the first record

hRecord.Clear();

hRecord.SetFieldAsSigned("Invoice", Invoice);// invoice

hRecord.SetFieldAsSigned("ItemNbr", 1); // invoice item

hRecord.SetFieldAsSigned("Quantity", 100); // item quantity

hRecord.SetFieldAsSigned("ItemCode", 1001); // item code

hRecord.InsertBatch(); // insert

// prepare the second record

hRecord.Clear();

hRecord.SetFieldAsSigned("Invoice", Invoice);// invoice

hRecord.SetFieldAsSigned("ItemNbr", 2); // invoice item

hRecord.SetFieldAsSigned("Quantity", 200); // item quantity

hRecord.SetFieldAsSigned("ItemCode", 1002); // item code

hRecord.InsertBatch(); // insert

// terminate the batch operation

hRecord.EndBatch();

}

catch (CTException& err)

{

printf("Batch failed with error %d\n", hRecord.GetError());

}

See Also

CTRecord::BatchLoaded(), CTRecord::BatchLocked(), CTRecord::BatchMode(), CTRecord::BatchTotal(), CTRecord::EndBatch(), CTRecord::IsBatchActive(), CTRecord::NextBatch(), CTRecord::SetBatch()

TOCIndex