Skip to content

Commit 88d684f

Browse files
antonbrianc
authored andcommitted
bugfix. sometimes native copy to loose rows
1 parent 583d059 commit 88d684f

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

lib/copystream.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ CopyToStream.prototype._outputDataChunk = function () {
114114
}
115115
if (this.buffer.length) {
116116
if (this._encoding) {
117-
this.emit('data', this.buffer.toString(encoding));
117+
this.emit('data', this.buffer.toString(this._encoding));
118118
} else {
119119
this.emit('data', this.buffer);
120120
}
121121
this.buffer = new Buffer(0);
122-
}
122+
}
123123
};
124124
CopyToStream.prototype._readable = function () {
125125
return !this._finished && !this._error;

lib/native/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ p.streamData = function (connection) {
8282
p.handleCopyFromChunk = function (chunk) {
8383
if ( this.stream ) {
8484
this.stream.handleChunk(chunk);
85-
}
85+
}
8686
//if there are no stream (for example when copy to query was sent by
8787
//query method instead of copyTo) error will be handled
8888
//on copyOutResponse event, so silently ignore this error here

src/binding.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ class Connection : public ObjectWrap {
487487
copied = PQgetCopyData(connection_, &buffer, 1);
488488
while (copied > 0) {
489489
chunk = Buffer::New(buffer, copied);
490-
Handle<Value> node_chunk = chunk->handle_;
490+
Local<Value> node_chunk = Local<Value>::New(chunk->handle_);
491491
Emit("copyData", &node_chunk);
492492
PQfreemem(buffer);
493493
copied = PQgetCopyData(connection_, &buffer, 1);

test/native/copyto-largedata-tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ test("COPY TO large amount of data from postgres", function () {
99
var con = new Client(helper.config),
1010
rowCount = 100000,
1111
stdoutStream = con.copyTo('COPY (select generate_series(1, ' + rowCount + ')) TO STDOUT');
12-
con.connect();
1312
stdoutStream.on('data', function () {
14-
rowCount --;
13+
rowCount--;
1514
});
1615
stdoutStream.on('end', function () {
17-
assert.equal(rowCount, 1, "copy to should load exactly requested number of rows" + rowCount);
16+
assert.equal(rowCount, 0, "copy to should load exactly requested number of rows");
1817
con.query("SELECT 1", assert.calls(function (error, result) {
1918
assert.ok(!error && result, "loading large amount of data by copy to should not break connection");
2019
con.end();
2120
}));
2221
});
22+
con.connect();
2323
});

0 commit comments

Comments
 (0)