Permalink
Browse files

Add ErrorPackets for multi result

  • Loading branch information...
1 parent f5bd13d commit a0542e455e8df749e5136ff0bddecacc650e54e8 @felixge felixge committed May 12, 2012
Showing with 43 additions and 0 deletions.
  1. +10 −0 lib/protocol/sequences/Query.js
  2. +33 −0 test/integration/test-multiple-statements-with-error.js
@@ -48,6 +48,16 @@ Query.prototype['OkPacket'] = function(packet) {
this._handleFinalResultPacket(packet);
};
+Query.prototype['ErrorPacket'] = function(packet) {
+ var err = Sequence.packetToError(packet);
+
+ var results = (this._results.length > 0)
+ ? this._results
+ : undefined;
+
+ this.end(err, results);
+};
+
Query.prototype['ResultSetHeaderPacket'] = function(packet) {
this._resultSet = new ResultSet(packet);
};
@@ -0,0 +1,33 @@
+var common = require('../common');
+var connection = common.createConnection();
+var assert = require('assert');
+
+var sql = [
+ 'SELECT 1',
+ 'invalid sql',
+ 'SELECT 2',
+].join('; ');
+
+var finishedQueryOne = false;
+connection.query(sql, function(err, results) {
+ assert.equal(finishedQueryOne, false);
+ finishedQueryOne = true;
+
+ assert.equal(err.code, 'ER_PARSE_ERROR');
+ assert.deepEqual(results, [[{1: 1}]]);
+});
+
+var finishedQueryTwo = false;
+connection.query('SELECT 3', function(err, results) {
+ assert.equal(finishedQueryTwo, false);
+ finishedQueryTwo = true;
+
+ assert.deepEqual(results, [{3: 3}]);
+});
+
+connection.end();
+
+process.on('exit', function() {
+ assert.equal(finishedQueryOne, true);
+ assert.equal(finishedQueryTwo, true);
+});

0 comments on commit a0542e4

Please sign in to comment.