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