diff --git a/lib/connection.js b/lib/connection.js index 49722c2d..ccc5571b 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -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 diff --git a/lib/query.js b/lib/query.js index a3330231..5f22a66b 100644 --- a/lib/query.js +++ b/lib/query.js @@ -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;