diff --git a/src/fb-cpp/Attachment.cpp b/src/fb-cpp/Attachment.cpp index 7dadf2d..6a7aaed 100644 --- a/src/fb-cpp/Attachment.cpp +++ b/src/fb-cpp/Attachment.cpp @@ -62,6 +62,12 @@ Attachment::Attachment(Client& client, const std::string& uri, const AttachmentO if (const auto forcedWrites = options.getForcedWrites()) dpbBuilder->insertInt(&statusWrapper, isc_dpb_force_write, *forcedWrites ? 1 : 0); + if (const auto maxInlineBlobSize = options.getMaxInlineBlobSize()) + dpbBuilder->insertInt(&statusWrapper, isc_dpb_max_inline_blob_size, static_cast(*maxInlineBlobSize)); + + if (const auto maxBlobCacheSize = options.getMaxBlobCacheSize()) + dpbBuilder->insertInt(&statusWrapper, isc_dpb_max_blob_cache_size, static_cast(*maxBlobCacheSize)); + auto dispatcher = fbRef(master->getDispatcher()); const auto dpbBuffer = dpbBuilder->getBuffer(&statusWrapper); const auto dpbBufferLen = dpbBuilder->getBufferLength(&statusWrapper); diff --git a/src/fb-cpp/Attachment.h b/src/fb-cpp/Attachment.h index 957b6b5..f164e3f 100644 --- a/src/fb-cpp/Attachment.h +++ b/src/fb-cpp/Attachment.h @@ -200,6 +200,46 @@ namespace fbcpp return *this; } + /// + /// Returns the maximum size of blobs the server may send inline with the rows + /// of a result set. + /// + const std::optional& getMaxInlineBlobSize() const + { + return maxInlineBlobSize; + } + + /// + /// Sets the maximum size of blobs the server may send inline with the rows of + /// a result set (`isc_dpb_max_inline_blob_size`), avoiding a round trip per blob + /// over remote connections. Zero disables inline blobs. + /// Requires Firebird 5.0.3 or later; ignored by older versions. + /// + AttachmentOptions& setMaxInlineBlobSize(std::uint32_t value) + { + maxInlineBlobSize = value; + return *this; + } + + /// + /// Returns the maximum size of the client-side cache for inline blobs. + /// + const std::optional& getMaxBlobCacheSize() const + { + return maxBlobCacheSize; + } + + /// + /// Sets the maximum size of the client-side cache for inline blobs + /// (`isc_dpb_max_blob_cache_size`). Zero disables inline blobs. + /// Requires Firebird 5.0.3 or later; ignored by older versions. + /// + AttachmentOptions& setMaxBlobCacheSize(std::uint32_t value) + { + maxBlobCacheSize = value; + return *this; + } + private: std::optional connectionCharSet; std::optional userName; @@ -207,6 +247,8 @@ namespace fbcpp std::optional role; std::optional sqlDialect; std::optional forcedWrites; + std::optional maxInlineBlobSize; + std::optional maxBlobCacheSize; std::vector dpb; bool createDatabase = false; }; diff --git a/src/test/Attachment.cpp b/src/test/Attachment.cpp index ca7b725..82dea23 100644 --- a/src/test/Attachment.cpp +++ b/src/test/Attachment.cpp @@ -860,4 +860,20 @@ BOOST_AUTO_TEST_CASE(resetSession) transaction2.commit(); } +BOOST_AUTO_TEST_CASE(inlineBlobOptions) +{ + const auto database = getTempFile("Attachment-inlineBlobOptions.fdb"); + Attachment attachment1{getClient(), database, AttachmentOptions().setCreateDatabase(true).setForcedWrites(false)}; + FbDropDatabase attachmentDrop{attachment1}; + + Attachment attachment2{ + getClient(), database, AttachmentOptions().setMaxInlineBlobSize(1000u).setMaxBlobCacheSize(200000u)}; + + impl::StatusWrapper statusWrapper{getClient()}; + BOOST_CHECK_EQUAL(attachment2.getHandle()->getMaxInlineBlobSize(&statusWrapper), 1000u); + BOOST_CHECK_EQUAL(attachment2.getHandle()->getMaxBlobCacheSize(&statusWrapper), 200000u); + + attachment2.disconnect(); +} + BOOST_AUTO_TEST_SUITE_END()