Restore LoadBlobFromFile

This commit is contained in:
Paul Reeves 2023-01-26 16:23:43 +01:00
parent 3a3cae7284
commit 331a27bf82

View File

@ -169,30 +169,28 @@ FB_UDR_END_FUNCTION
/*** DDL
create or alter function LoadBlobFromFile (
afilename varchar(8191),
ablob BLOB
) returns bigint
external name 'MyFirstUDRKit!MFK_Load_Blob_From_File!Load file and save to Blob'
engine udr;
***/
static const size_t MaxSegmentSize = 65535;
FB_UDR_BEGIN_FUNCTION(MFK_Load_Blob_From_File)
* create or alter function LoadBlobFromFile (
* afilename varchar(8191),
* ablob BLOB
* ) returns bigint
* external name 'MyFirstUDRKit!MFKLoadBlobFromFile!Load file and save to Blob'
* engine udr;
***/
FB_UDR_BEGIN_FUNCTION (MFK_LoadBlobFromFile)
//BEGIN
FB_UDR_MESSAGE(InMessage,
(FB_CHAR(8191), afilename)
(FB_BLOB, ablob)
);
FB_UDR_MESSAGE(OutMessage,
(FB_BLOB, ablob)
(FB_BIGINT, result)
);
AutoRelease<IAttachment> att;
AutoRelease<ITransaction> tra;
AutoRelease<IBlob> Blob;
FB_UDR_EXECUTE_FUNCTION
{
@ -208,7 +206,8 @@ FB_UDR_EXECUTE_FUNCTION
return;
}
AutoRelease<IBlob> Blob(att->createBlob(status, tra, &out->ablob, 0, nullptr));
// 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;
@ -217,7 +216,7 @@ FB_UDR_EXECUTE_FUNCTION
vector<char> Buffer (MaxSegmentSize, 0);
streamsize DataSize;
while ( !File.good() ) {
while ( File.good() ) {
File.read( Buffer.data(), Buffer.size() );
DataSize = File.gcount();
Blob->putSegment( status, DataSize, Buffer.data() );