This commit is contained in:
Paul Reeves 2023-02-02 09:18:00 +01:00
parent 3d49fa4f94
commit 9746ae578d

View File

@ -24,13 +24,13 @@
*/ */
#define FB_UDR_STATUS_TYPE ::Firebird::ThrowStatusWrapper
//#include <ibase.h>
//#include <firebird/UdrCppEngine.h>
#include "MyFirstUDRKit.h" #include "MyFirstUDRKit.h"
#include <ibase.h>
#include <firebird/UdrCppEngine.h>
#include "UdrCppTemplates.h"
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
@ -68,7 +68,6 @@
#include <limits> #include <limits>
using namespace std;
using namespace Firebird; using namespace Firebird;
@ -185,7 +184,7 @@ FB_UDR_MESSAGE(OutMessage,
AutoRelease<IAttachment> att; AutoRelease<IAttachment> att;
AutoRelease<ITransaction> tra; AutoRelease<ITransaction> tra;
AutoRelease<IBlob> Blob; AutoRelease<IBlob> blob;
FB_UDR_EXECUTE_FUNCTION FB_UDR_EXECUTE_FUNCTION
{ {
@ -206,12 +205,9 @@ FB_UDR_EXECUTE_FUNCTION
att.reset(context->getAttachment(status)); att.reset(context->getAttachment(status));
tra.reset(context->getTransaction(status)); tra.reset(context->getTransaction(status));
blob.reset(att->openBlob(status, tra, &in->ablob, 0, nullptr));
// This is wrong - the calling application should pass in a blob handle if (blob == nullptr) {
//AutoRelease<IBlob> 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; out->result = -1;
return; return;
} }
@ -222,7 +218,9 @@ FB_UDR_EXECUTE_FUNCTION
while ( FileReader.good() ) { while ( FileReader.good() ) {
FileReader.read( Buffer.data(), Buffer.size() ); FileReader.read( Buffer.data(), Buffer.size() );
DataSize = FileReader.gcount(); DataSize = FileReader.gcount();
Blob->putSegment( status, DataSize, Buffer.data() ); // fail seems to be here...
// Probably need to declare buffer differently.
blob->putSegment( status, DataSize, Buffer.data() );
out->result += DataSize; out->result += DataSize;
// Perhaps test for badbit here? // Perhaps test for badbit here?
} }
@ -230,16 +228,17 @@ FB_UDR_EXECUTE_FUNCTION
// What to do? // What to do?
out->resultNull = FB_TRUE; out->resultNull = FB_TRUE;
// What do we do with the partially written blob? Is cancel enough? // What do we do with the partially written blob? Is cancel enough?
Blob->cancel( status ); blob->cancel( status );
// Should we reset result to 0? // Should we reset result to 0?
} }
Blob->close( status ); blob->close( status );
Blob->release(); blob->release();
Buffer.clear(); Buffer.clear();
} }
catch (...) catch (...)
{ {
// This generates an unrecognised C++ exception, which is insufficient.
throw std::runtime_error("Error writing stream to BLOB."); throw std::runtime_error("Error writing stream to BLOB.");
} }
@ -291,7 +290,7 @@ FB_UDR_EXECUTE_FUNCTION
* DOC NOTE - We do not test for existence of the file here! * DOC NOTE - We do not test for existence of the file here!
*/ */
fstream File ( in->afilename.str , fstream::out | fstream::binary | fstream::app ); std::fstream File ( in->afilename.str , std::fstream::out | std::fstream::binary | std::fstream::app );
if (! File.is_open()) { if (! File.is_open()) {
out->result = -2; out->result = -2;
return; return;
@ -305,7 +304,7 @@ FB_UDR_EXECUTE_FUNCTION
} }
vector<char> Buffer (MaxSegmentSize, 0); std::vector<char> Buffer (MaxSegmentSize, 0);
unsigned BytesRead = 0; unsigned BytesRead = 0;