Add Batch Execution support (IBatch wrapper) (#26)#40
Open
fdcastel wants to merge 3 commits intoasfernandes:mainfrom
Open
Add Batch Execution support (IBatch wrapper) (#26)#40fdcastel wants to merge 3 commits intoasfernandes:mainfrom
fdcastel wants to merge 3 commits intoasfernandes:mainfrom
Conversation
Add Batch, BatchOptions, BatchCompletionState, and BlobPolicy types that wrap the Firebird IBatch interface for bulk DML operations. Two creation paths: - From a prepared Statement (IStatement::createBatch) - From an Attachment + SQL text (IAttachment::createBatch) Also adds getAttachment() and getInputMessage() accessors to Statement.
asfernandes
reviewed
Feb 25, 2026
Owner
asfernandes
left a comment
There was a problem hiding this comment.
I do want more time to review the interfaces.
Batch is not something I'm very aware and some of the interfaces appears very raw (as native ones) for me.
Add rules from PR asfernandes#40 review: - Use lowercase suffixes for numeric literals (1u, not 1U) - Do not use string literals in assert() expressions - Do not explicitly define destructor as = default unless necessary - Prefer vector iterator-range constructor over allocate + memcpy
- Remove string literal from assert() expression - Fix brace style: remove braces from single-line if, add braces to multi-line if - Use vector iterator-range constructor instead of allocate + memcpy - Remove unnecessary explicit default destructor on BatchCompletionState - Rename getMetadata() to getInputMetadata() for consistency with Statement - Add getInputDescriptors() with lazy descriptor caching - Fix numeric suffix casing: U -> u in all test assertions
Contributor
Author
|
Requested changes pushed. I also took the liberty of updating AGENTS.md in a separate commit. Feel free to ignore or modify those updates as needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #26
Summary
Adds a new
Batchclass that wraps the FirebirdIBatchinterface, enablingbulk DML operations (INSERT/UPDATE/DELETE) with a single server round-trip.
This is the primary performance path for ETL workloads against Firebird 4.0+
and maps directly to ODBC's "array of parameter values" feature
(
SQL_ATTR_PARAMSET_SIZE > 1).New types
BlobPolicyNONE,ID_ENGINE,ID_USER,STREAMBatchOptionsBatchCompletionStateIBatchCompletionState— provides per-message execution results, error lookup, and detailed error statusBatchIBatch— collects messages and executes them in bulkCreation paths
Two constructors for
Batch:Statement— usesIStatement::createBatch(). Enablesthe convenience
addMessage()method that copies the Statement's currentinput-message buffer into the batch.
Attachment+ SQL text — usesIAttachment::createBatch().Messages are added via the raw
add()method.API overview
Blob support
addBlob()— inline blob with engine-generated or user-generated IDappendBlobData()— append to the last inline blobaddBlobStream()— stream-mode blob dataregisterBlob()— register an existingBlobfor batch usesetDefaultBpb()— set default blob parameter blockgetBlobAlignment()— query alignment requirementMinor additions to
StatementgetAttachment()— returns theAttachment&used to create the statementgetInputMessage()— provides access to the raw input message buffer (usedby
Batch::addMessage())Files changed
src/fb-cpp/Batch.hBlobPolicy,BatchOptions,BatchCompletionState,Batchsrc/fb-cpp/Batch.cppsrc/test/Batch.cppsrc/fb-cpp/Statement.hgetAttachment()andgetInputMessage()accessorssrc/fb-cpp/fb-cpp.h#include "Batch.h"Test cases
constructorFromStatementAndExecuteaddMessage(), record counts, data verificationconstructorFromAttachmentAndExecuteadd(), metadata-driven message buildingmoveConstructorTransfersOwnershipexecuteReportsNoInfoWhenRecordCountsDisabledSUCCESS_NO_INFOwhen record counts are offexecuteWithBadDataReportsExecuteFailedEXECUTE_FAILED,findError()locates the failure, multi-error allows partial successcancelDiscardsMessagescancel()invalidates the handle, nothing is insertedblobWithIdEngineaddBlob()withBlobPolicy::ID_ENGINE, content verifiedregisterExistingBlobBlobregistered in batch viaregisterBlob(), content verifiedcloseReleasesHandleclose()invalidates the handleDesign notes
Blob,Statement, andTransaction.BatchCompletionState::findError()returnsstd::optional<unsigned>insteadof the raw
0xFFFFFFFFsentinel — idiomatic modern C++.BatchCompletionStateis disposable (not reference-counted), so the handleis held via
FbUniquePtrand disposed in the destructor.Batchholds aFbRef<fb::IBatch>(reference-counted) consistent with howStatementholds itsIStatementhandle.IBatchrequires Firebird 4.0+. On older servers,createBatch()will throwa
DatabaseException.