Merge pull request #242 from CartoDB/master-error-on-missing-stream

Cleanly handle missing stream error on COPY operation. Closes #241
This commit is contained in:
Brian C 2013-01-16 08:46:26 -08:00
commit bd04758a84
2 changed files with 13 additions and 3 deletions

View File

@ -267,6 +267,11 @@ p.sendCopyFromChunk = function (chunk) {
p.endCopyFrom = function () {
this.stream.write(this.writer.add(emptyBuffer).flush(0x63));
}
p.sendCopyFail = function (msg) {
//this.stream.write(this.writer.add(emptyBuffer).flush(0x66));
this.writer.addCString(msg);
this._send(0x66);
}
//parsing methods
p.setBuffer = function(buffer) {
if(this.lastBuffer) { //we have unfinished biznaz

View File

@ -17,7 +17,7 @@ var Query = function(config, values, callback) {
this.types = config.types;
this.name = config.name;
this.binary = config.binary;
this.stream = config.stream;
this.stream = config.stream;
//use unique portal name each time
this.portal = config.portal || ""
this.callback = config.callback;
@ -170,9 +170,14 @@ p.prepare = function(connection) {
this.getRows(connection);
};
p.streamData = function (connection) {
this.stream.startStreamingToConnection(connection);
if ( this.stream ) this.stream.startStreamingToConnection(connection);
else connection.sendCopyFail('No source stream defined');
};
p.handleCopyFromChunk = function (chunk) {
this.stream.handleChunk(chunk);
if ( this.stream ) this.stream.handleChunk(chunk);
else {
// TODO: signal the problem somehow
//this.handleError(new Error('error', 'No destination stream defined'));
}
}
module.exports = Query;