diff --git a/src/MyFirstUDRKit.cpp b/src/MyFirstUDRKit.cpp index c07fd8b..bbece68 100644 --- a/src/MyFirstUDRKit.cpp +++ b/src/MyFirstUDRKit.cpp @@ -24,13 +24,13 @@ */ -#define FB_UDR_STATUS_TYPE ::Firebird::ThrowStatusWrapper - -//#include -//#include #include "MyFirstUDRKit.h" +#include +#include +#include "UdrCppTemplates.h" + #include #include #include @@ -68,7 +68,6 @@ #include -using namespace std; using namespace Firebird; @@ -185,7 +184,7 @@ FB_UDR_MESSAGE(OutMessage, AutoRelease att; AutoRelease tra; -AutoRelease Blob; +AutoRelease blob; FB_UDR_EXECUTE_FUNCTION { @@ -206,12 +205,9 @@ FB_UDR_EXECUTE_FUNCTION att.reset(context->getAttachment(status)); tra.reset(context->getTransaction(status)); + blob.reset(att->openBlob(status, tra, &in->ablob, 0, nullptr)); - // This is wrong - the calling application should pass in a blob handle - //AutoRelease 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; return; } @@ -222,7 +218,9 @@ FB_UDR_EXECUTE_FUNCTION while ( FileReader.good() ) { FileReader.read( Buffer.data(), Buffer.size() ); DataSize = FileReader.gcount(); - Blob->putSegment( status, DataSize, Buffer.data() ); + // fail seems to be here... + // Probably need to declare buffer differently. + blob->putSegment( status, DataSize, Buffer.data() ); out->result += DataSize; // Perhaps test for badbit here? } @@ -230,16 +228,17 @@ FB_UDR_EXECUTE_FUNCTION // What to do? out->resultNull = FB_TRUE; // What do we do with the partially written blob? Is cancel enough? - Blob->cancel( status ); + blob->cancel( status ); // Should we reset result to 0? } - Blob->close( status ); - Blob->release(); + blob->close( status ); + blob->release(); Buffer.clear(); } catch (...) { + // This generates an unrecognised C++ exception, which is insufficient. throw std::runtime_error("Error writing stream to BLOB."); } @@ -291,7 +290,7 @@ FB_UDR_EXECUTE_FUNCTION * DOC NOTE - We do not test for existence of the file here! */ - fstream File ( in->afilename.str , fstream::out | fstream::binary | fstream::app ); + std::fstream File ( in->afilename.str , std::fstream::out | std::fstream::binary | std::fstream::app ); if (! File.is_open()) { out->result = -2; return; @@ -305,7 +304,7 @@ FB_UDR_EXECUTE_FUNCTION } - vector Buffer (MaxSegmentSize, 0); + std::vector Buffer (MaxSegmentSize, 0); unsigned BytesRead = 0;