diff --git a/lib/protocol/Protocol.js b/lib/protocol/Protocol.js index ab371059b..256f8d560 100644 --- a/lib/protocol/Protocol.js +++ b/lib/protocol/Protocol.js @@ -336,6 +336,14 @@ Protocol.prototype._dequeue = function(sequence) { return; } + if (sequence !== this._queue[0]) { + var idx = this._queue.indexOf(sequence); + if (idx > 0) { + this._queue.splice(idx, 1); + } + return; + } + this._queue.shift(); var sequence = this._queue[0]; diff --git a/lib/protocol/sequences/Query.js b/lib/protocol/sequences/Query.js index b7632959b..3af04368e 100644 --- a/lib/protocol/sequences/Query.js +++ b/lib/protocol/sequences/Query.js @@ -24,12 +24,29 @@ function Query(options, callback) { this._fields = []; this._index = 0; this._loadError = null; + this._started = false; } Query.prototype.start = function() { + this._started = true; this.emit('packet', new Packets.ComQueryPacket(this.sql)); }; +Query.prototype.started = function() { + return this._started; +}; + +Query.prototype.ended = function() { + return this._ended; +}; + +Query.prototype.dequeue = function() { + if (this._started) { + throw new Error('Query already started.'); + } + this.end(); +}; + Query.prototype.determinePacket = function determinePacket(byte, parser) { var resultSet = this._resultSet;