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