From ba94fe6d9954a9eab8b9ee0a082788a023a41bd0 Mon Sep 17 00:00:00 2001 From: Paul Reeves Date: Wed, 1 Feb 2023 21:37:06 +0100 Subject: [PATCH] Rework writing to blob --- src/MyFirstUDRKit.cpp | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/MyFirstUDRKit.cpp b/src/MyFirstUDRKit.cpp index bb9a1a2..c07fd8b 100644 --- a/src/MyFirstUDRKit.cpp +++ b/src/MyFirstUDRKit.cpp @@ -202,15 +202,22 @@ FB_UDR_EXECUTE_FUNCTION return; } - // This is wrong - the calling application should pass in a blob handle - AutoRelease Blob(att->createBlob(status, tra, &in->ablob, 0, nullptr)); - if (Blob == nullptr) { - out->result = -1; - return; - } + try { - vector Buffer (MaxSegmentSize, 0); - streamsize DataSize; + att.reset(context->getAttachment(status)); + tra.reset(context->getTransaction(status)); + + // This is wrong - the calling application should pass in a blob handle + //AutoRelease Blob(att->openBlob(status, tra, &in->ablob, 0, nullptr)); + Blob.reset(att->openBlob(status, tra, &in->ablob, 0, nullptr)); + + if (Blob == nullptr) { + out->result = -1; + return; + } + + std::vector Buffer (MaxSegmentSize, 0); + std::streamsize DataSize; while ( FileReader.good() ) { FileReader.read( Buffer.data(), Buffer.size() ); @@ -227,12 +234,17 @@ FB_UDR_EXECUTE_FUNCTION // Should we reset result to 0? } + Blob->close( status ); + Blob->release(); + Buffer.clear(); + } + catch (...) + { + throw std::runtime_error("Error writing stream to BLOB."); + } - Blob->close( status ); - Blob->release(); - - Buffer.clear(); - File.close(); + FileReader.close(); + out->result = 1; }