Skip to content

Commit

Permalink
Fixed CLOB UTF8 bug where value would be truncated and padded with
Browse files Browse the repository at this point in the history
null characters when multi-byte charset is set.

Implemented by getting the chunkSize of the CLOB, then reading
that many bytes at a time, rather than getting the number of characters
(clob.length()) and only reading the equivalent number of bytes (which
fails for multi-byte characters).
  • Loading branch information
johannish authored and raztus committed Jul 24, 2013
1 parent a2766a0 commit 43655a1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,23 @@ Local<Object> Connection::CreateV8ObjectFromRow(std::vector<column_t*> columns,
break;
}

int clobLength = v->length();
oracle::occi::Stream *instream = v->getStream(1,0);
char *buffer = new char[clobLength];
memset(buffer, 0, clobLength);
instream->readBuffer(buffer, clobLength);
// chunk size is set when the table is created
size_t chunkSize = v->getChunkSize();
char *buffer = new char[chunkSize];
memset(buffer, 0, chunkSize);
std::string columnVal;
int numBytesRead = instream->readBuffer(buffer, chunkSize);
int totalBytesRead = 0;
while (numBytesRead != -1) {
totalBytesRead += numBytesRead;
columnVal.append(buffer);
numBytesRead = instream->readBuffer(buffer, chunkSize);
}

v->closeStream(instream);
v->close();
obj->Set(String::New(col->name.c_str()), String::New(buffer, clobLength));
obj->Set(String::New(col->name.c_str()), String::New(columnVal.c_str(), totalBytesRead));
delete v;
delete [] buffer;
}
Expand Down

0 comments on commit 43655a1

Please sign in to comment.