mirror of
https://github.com/brianc/node-postgres.git
synced 2026-02-01 16:47:23 +00:00
bugfix. sometimes native copy to loose rows
This commit is contained in:
parent
583d059947
commit
88d684f925
@ -114,12 +114,12 @@ 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);
|
||||||
}
|
}
|
||||||
this.buffer = new Buffer(0);
|
this.buffer = new Buffer(0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
CopyToStream.prototype._readable = function () {
|
CopyToStream.prototype._readable = function () {
|
||||||
return !this._finished && !this._error;
|
return !this._finished && !this._error;
|
||||||
|
|||||||
@ -82,7 +82,7 @@ p.streamData = function (connection) {
|
|||||||
p.handleCopyFromChunk = function (chunk) {
|
p.handleCopyFromChunk = function (chunk) {
|
||||||
if ( this.stream ) {
|
if ( this.stream ) {
|
||||||
this.stream.handleChunk(chunk);
|
this.stream.handleChunk(chunk);
|
||||||
}
|
}
|
||||||
//if there are no stream (for example when copy to query was sent by
|
//if there are no stream (for example when copy to query was sent by
|
||||||
//query method instead of copyTo) error will be handled
|
//query method instead of copyTo) error will be handled
|
||||||
//on copyOutResponse event, so silently ignore this error here
|
//on copyOutResponse event, so silently ignore this error here
|
||||||
|
|||||||
@ -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…
x
Reference in New Issue
Block a user