Rework writing to blob

This commit is contained in:
Paul Reeves 2023-02-01 21:37:06 +01:00
parent c092e8fa8f
commit ba94fe6d99

View File

@ -202,15 +202,22 @@ FB_UDR_EXECUTE_FUNCTION
return; return;
} }
try {
att.reset(context->getAttachment(status));
tra.reset(context->getTransaction(status));
// This is wrong - the calling application should pass in a blob handle // This is wrong - the calling application should pass in a blob handle
AutoRelease<IBlob> Blob(att->createBlob(status, tra, &in->ablob, 0, 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) { if (Blob == nullptr) {
out->result = -1; out->result = -1;
return; return;
} }
vector<char> Buffer (MaxSegmentSize, 0); std::vector<char> Buffer (MaxSegmentSize, 0);
streamsize DataSize; std::streamsize DataSize;
while ( FileReader.good() ) { while ( FileReader.good() ) {
FileReader.read( Buffer.data(), Buffer.size() ); FileReader.read( Buffer.data(), Buffer.size() );
@ -227,12 +234,17 @@ FB_UDR_EXECUTE_FUNCTION
// 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();
File.close(); }
catch (...)
{
throw std::runtime_error("Error writing stream to BLOB.");
}
FileReader.close();
out->result = 1;
} }