fb-cpp 0.0.2
A modern C++ wrapper for the Firebird database API
Loading...
Searching...
No Matches
fbcpp::Batch Class Referencefinal

Wraps the Firebird IBatch interface for bulk DML operations. More...

#include <Batch.h>

Public Member Functions

 Batch (Statement &statement, Transaction &transaction, const BatchOptions &options={})
 Creates a Batch from a prepared Statement.
 
 Batch (Attachment &attachment, Transaction &transaction, std::string_view sql, unsigned dialect=3, const BatchOptions &options={})
 Creates a Batch from an Attachment and SQL text.
 
 Batch (Batch &&o) noexcept
 Transfers ownership of another Batch into this one.
 
Batchoperator= (Batch &&)=delete
 Move assignment is not supported.
 
 Batch (const Batch &)=delete
 Copy construction is not supported.
 
Batchoperator= (const Batch &)=delete
 Copy assignment is not supported.
 
 ~Batch () noexcept
 Closes the batch handle if still valid.
 
bool isValid () const noexcept
 Returns whether the batch handle is valid.
 
Adding messages
void add (unsigned count, const void *inBuffer)
 Adds one or more raw messages to the batch buffer.
 
void addMessage ()
 Adds the Statement's current input-message buffer as one message.
 
Blob support
BlobId addBlob (std::span< const std::byte > data, const BlobOptions &bpb={})
 Adds an inline blob and returns its batch-local ID.
 
void appendBlobData (std::span< const std::byte > data)
 Appends more data to the last blob added with addBlob().
 
void addBlobStream (std::span< const std::byte > data)
 Adds blob data in stream mode (BlobPolicy::STREAM only).
 
BlobId registerBlob (const BlobId &existingBlob)
 Registers an existing blob (created via the normal Blob class) for use in the batch, and returns its batch-local ID.
 
void setDefaultBpb (const BlobOptions &bpb)
 Sets the default BPB (Blob Parameter Block) for blobs in this batch.
 
unsigned getBlobAlignment ()
 Returns the blob alignment requirement for this batch.
 
Execution
BatchCompletionState execute ()
 Executes all queued messages and returns the completion state.
 
void cancel ()
 Cancels the batch, discarding all queued messages.
 
void close ()
 Closes the batch handle and releases resources.
 
FbRef< fb::IMessageMetadata > getInputMetadata ()
 Returns the input metadata for this batch.
 
const std::vector< Descriptor > & getInputDescriptors ()
 Returns cached input parameter descriptors for this batch.
 

Detailed Description

Wraps the Firebird IBatch interface for bulk DML operations.

A Batch collects multiple parameter sets ("messages") and sends them to the server in a single round-trip for execution. This maps directly to ODBC's "array of parameter values" feature (SQL_ATTR_PARAMSET_SIZE > 1) and is the primary performance path for ETL workloads against Firebird 4.0+.

Two creation paths are supported:

  • From a prepared Statement — uses IStatement::createBatch(). The Statement must remain valid for the lifetime of the Batch. The convenience method addMessage() copies the Statement's current input-message buffer into the batch.
  • From an **Attachment + SQL text** — uses IAttachment::createBatch(). Messages must be added via the raw add() method.

Definition at line 274 of file Batch.h.

Constructor & Destructor Documentation

◆ Batch() [1/3]

Batch::Batch ( Statement statement,
Transaction transaction,
const BatchOptions options = {} 
)
explicit

Creates a Batch from a prepared Statement.

The Statement must remain valid for the lifetime of the Batch.

Definition at line 101 of file Batch.cpp.

◆ Batch() [2/3]

Batch::Batch ( Attachment attachment,
Transaction transaction,
std::string_view  sql,
unsigned  dialect = 3,
const BatchOptions options = {} 
)
explicit

Creates a Batch from an Attachment and SQL text.

Definition at line 117 of file Batch.cpp.

◆ Batch() [3/3]

Batch::Batch ( Batch &&  o)
noexcept

Transfers ownership of another Batch into this one.

Definition at line 134 of file Batch.cpp.

◆ ~Batch()

fbcpp::Batch::~Batch ( )
inlinenoexcept

Closes the batch handle if still valid.

Definition at line 313 of file Batch.h.

Member Function Documentation

◆ add()

void Batch::add ( unsigned  count,
const void *  inBuffer 
)

Adds one or more raw messages to the batch buffer.

inBuffer must contain count aligned messages matching the input metadata.

Definition at line 147 of file Batch.cpp.

◆ addBlob()

BlobId Batch::addBlob ( std::span< const std::byte >  data,
const BlobOptions bpb = {} 
)

Adds an inline blob and returns its batch-local ID.

Only valid when BlobPolicy is ID_ENGINE or ID_USER.

Definition at line 163 of file Batch.cpp.

◆ addBlobStream()

void Batch::addBlobStream ( std::span< const std::byte >  data)

Adds blob data in stream mode (BlobPolicy::STREAM only).

Definition at line 182 of file Batch.cpp.

◆ addMessage()

void Batch::addMessage ( )

Adds the Statement's current input-message buffer as one message.

Requires the Statement-based constructor. Typical usage:

stmt.setInt32(0, val);
batch.addMessage();

Definition at line 153 of file Batch.cpp.

◆ appendBlobData()

void Batch::appendBlobData ( std::span< const std::byte >  data)

Appends more data to the last blob added with addBlob().

Definition at line 176 of file Batch.cpp.

◆ cancel()

void Batch::cancel ( )

Cancels the batch, discarding all queued messages.

Definition at line 224 of file Batch.cpp.

◆ close()

void Batch::close ( )

Closes the batch handle and releases resources.

Definition at line 231 of file Batch.cpp.

◆ execute()

BatchCompletionState Batch::execute ( )

Executes all queued messages and returns the completion state.

Definition at line 215 of file Batch.cpp.

◆ getBlobAlignment()

unsigned Batch::getBlobAlignment ( )

Returns the blob alignment requirement for this batch.

Definition at line 206 of file Batch.cpp.

◆ getInputDescriptors()

const std::vector< Descriptor > & Batch::getInputDescriptors ( )

Returns cached input parameter descriptors for this batch.

Definition at line 248 of file Batch.cpp.

◆ getInputMetadata()

FbRef< fb::IMessageMetadata > Batch::getInputMetadata ( )

Returns the input metadata for this batch.

Definition at line 238 of file Batch.cpp.

◆ isValid()

bool fbcpp::Batch::isValid ( ) const
inlinenoexcept

Returns whether the batch handle is valid.

Definition at line 332 of file Batch.h.

◆ registerBlob()

BlobId Batch::registerBlob ( const BlobId existingBlob)

Registers an existing blob (created via the normal Blob class) for use in the batch, and returns its batch-local ID.

Definition at line 188 of file Batch.cpp.

◆ setDefaultBpb()

void Batch::setDefaultBpb ( const BlobOptions bpb)

Sets the default BPB (Blob Parameter Block) for blobs in this batch.

Definition at line 198 of file Batch.cpp.


The documentation for this class was generated from the following files: