bugfix. sometimes native copy to loose rows
This commit is contained in:
parent
583d059947
commit
88d684f925
@ -114,7 +114,7 @@ CopyToStream.prototype._outputDataChunk = function () {
|
|||||||
}
|
}
|
||||||
if (this.buffer.length) {
|
if (this.buffer.length) {
|
||||||
if (this._encoding) {
|
if (this._encoding) {
|
||||||
this.emit('data', this.buffer.toString(encoding));
|
this.emit('data', this.buffer.toString(this._encoding));
|
||||||
} else {
|
} else {
|
||||||
this.emit('data', this.buffer);
|
this.emit('data', this.buffer);
|
||||||
}
|
}
|
||||||
|
@ -487,7 +487,7 @@ protected:
|
|||||||
copied = PQgetCopyData(connection_, &buffer, 1);
|
copied = PQgetCopyData(connection_, &buffer, 1);
|
||||||
while (copied > 0) {
|
while (copied > 0) {
|
||||||
chunk = Buffer::New(buffer, copied);
|
chunk = Buffer::New(buffer, copied);
|
||||||
Handle<Value> node_chunk = chunk->handle_;
|
Local<Value> node_chunk = Local<Value>::New(chunk->handle_);
|
||||||
Emit("copyData", &node_chunk);
|
Emit("copyData", &node_chunk);
|
||||||
PQfreemem(buffer);
|
PQfreemem(buffer);
|
||||||
copied = PQgetCopyData(connection_, &buffer, 1);
|
copied = PQgetCopyData(connection_, &buffer, 1);
|
||||||
|
@ -9,15 +9,15 @@ test("COPY TO large amount of data from postgres", function () {
|
|||||||
var con = new Client(helper.config),
|
var con = new Client(helper.config),
|
||||||
rowCount = 100000,
|
rowCount = 100000,
|
||||||
stdoutStream = con.copyTo('COPY (select generate_series(1, ' + rowCount + ')) TO STDOUT');
|
stdoutStream = con.copyTo('COPY (select generate_series(1, ' + rowCount + ')) TO STDOUT');
|
||||||
con.connect();
|
|
||||||
stdoutStream.on('data', function () {
|
stdoutStream.on('data', function () {
|
||||||
rowCount --;
|
rowCount--;
|
||||||
});
|
});
|
||||||
stdoutStream.on('end', function () {
|
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) {
|
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");
|
assert.ok(!error && result, "loading large amount of data by copy to should not break connection");
|
||||||
con.end();
|
con.end();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
con.connect();
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user