Skip to content

Commit 50b0284

Browse files
committed
Update connection.cpp
Fix for out parameter type CLOB
1 parent 2fe2aaf commit 50b0284

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/connection.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -723,16 +723,23 @@ void Connection::handleResult(ExecuteBaton* baton, Handle<Value> (&argv)[2]) {
723723
case OutParam::OCCICLOB:
724724
{
725725
output->clobVal.open(oracle::occi::OCCI_LOB_READONLY);
726-
int lobLength = output->clobVal.length();
727-
oracle::occi::Stream* instream = output->clobVal.getStream(1,0);
728-
char *buffer = new char[lobLength];
729-
memset(buffer, 0, lobLength);
730-
instream->readBuffer(buffer, lobLength);
731-
output->clobVal.closeStream(instream);
732-
output->clobVal.close();
733-
obj->Set(String::New(returnParam.c_str()), String::New(buffer, lobLength));
734-
delete [] buffer;
735-
break;
726+
oracle::occi::Stream* instream = output->clobVal.getStream(1,0);
727+
size_t chunkSize = output->clobVal.getChunkSize();
728+
char *buffer = new char[chunkSize];
729+
memset(buffer, 0, chunkSize);
730+
std::string clobVal;
731+
int numBytesRead = instream->readBuffer(buffer, chunkSize);
732+
int totalBytesRead = 0;
733+
while (numBytesRead != -1) {
734+
totalBytesRead += numBytesRead;
735+
clobVal.append(buffer);
736+
numBytesRead = instream->readBuffer(buffer, chunkSize);
737+
}
738+
output->clobVal.closeStream(instream);
739+
output->clobVal.close();
740+
obj->Set(String::New(returnParam.c_str()), String::New(clobVal.c_str(), totalBytesRead));
741+
delete [] buffer;
742+
break;
736743
}
737744
case OutParam::OCCIBLOB:
738745
{

0 commit comments

Comments
 (0)