bugfix. sometimes native copy to loose rows

This commit is contained in:
anton 2013-01-18 22:11:16 +02:00 committed by bmc
parent 583d059947
commit 88d684f925
4 changed files with 7 additions and 7 deletions

View File

@ -114,12 +114,12 @@ CopyToStream.prototype._outputDataChunk = function () {
}
if (this.buffer.length) {
if (this._encoding) {
this.emit('data', this.buffer.toString(encoding));
this.emit('data', this.buffer.toString(this._encoding));
} else {
this.emit('data', this.buffer);
}
this.buffer = new Buffer(0);
}
}
};
CopyToStream.prototype._readable = function () {
return !this._finished && !this._error;

View File

@ -82,7 +82,7 @@ p.streamData = function (connection) {
p.handleCopyFromChunk = function (chunk) {
if ( this.stream ) {
this.stream.handleChunk(chunk);
}
}
//if there are no stream (for example when copy to query was sent by
//query method instead of copyTo) error will be handled
//on copyOutResponse event, so silently ignore this error here

View File

@ -487,7 +487,7 @@ protected:
copied = PQgetCopyData(connection_, &buffer, 1);
while (copied > 0) {
chunk = Buffer::New(buffer, copied);
Handle<Value> node_chunk = chunk->handle_;
Local<Value> node_chunk = Local<Value>::New(chunk->handle_);
Emit("copyData", &node_chunk);
PQfreemem(buffer);
copied = PQgetCopyData(connection_, &buffer, 1);

View File

@ -9,15 +9,15 @@ test("COPY TO large amount of data from postgres", function () {
var con = new Client(helper.config),
rowCount = 100000,
stdoutStream = con.copyTo('COPY (select generate_series(1, ' + rowCount + ')) TO STDOUT');
con.connect();
stdoutStream.on('data', function () {
rowCount --;
rowCount--;
});
stdoutStream.on('end', function () {
assert.equal(rowCount, 1, "copy to should load exactly requested number of rows" + rowCount);
assert.equal(rowCount, 0, "copy to should load exactly requested number of rows");
con.query("SELECT 1", assert.calls(function (error, result) {
assert.ok(!error && result, "loading large amount of data by copy to should not break connection");
con.end();
}));
});
con.connect();
});