Rework writing to blob

This commit is contained in:
Paul Reeves 2023-02-01 21:37:06 +01:00
parent c092e8fa8f
commit ba94fe6d99
1 changed files with 25 additions and 13 deletions

View File

@ -202,15 +202,22 @@ FB_UDR_EXECUTE_FUNCTION
return;
}
// This is wrong - the calling application should pass in a blob handle
AutoRelease<IBlob> Blob(att->createBlob(status, tra, &in->ablob, 0, nullptr));
if (Blob == nullptr) {
out->result = -1;
return;
}
try {
vector<char> 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<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() ) {
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;
}