Skip to content
This repository
  • 4 commits
  • 7 files changed
  • 0 comments
  • 1 contributor
Aug 22, 2010
Felix Geisendörfer Add a basic debug mode 1072c1b
Felix Geisendörfer Add failing sequential query test 1f36260
Felix Geisendörfer Fix: Sequential queries were broken
The parser did not correctly reset itself after receiving the final EOF packet
of a result set. This patch fixes this.

Fixes issue #1: http://github.com/felixge/node-mysql/issues/#issue/1
94ce814
Felix Geisendörfer Bump version d668f10
24  lib/mysql/client.js
@@ -24,6 +24,7 @@ function Client(config) {
24 24
   this.flags = Client.defaultFlags;
25 25
   this.maxPacketSize = 0x01000000;
26 26
   this.charsetNumber = 8;
  27
+  this.debug = false;
27 28
 
28 29
   this._queue = [];
29 30
   this._connection = null;
@@ -113,6 +114,10 @@ Client.prototype.query = function(sql, params, cb) {
113 114
 };
114 115
 
115 116
 Client.prototype.write = function(packet) {
  117
+  if (this.debug) {
  118
+    console.log('-> %s', packet.buffer.inspect());
  119
+  }
  120
+
116 121
   this._connection.write(packet.buffer);
117 122
 };
118 123
 
@@ -180,6 +185,10 @@ Client.prototype._dequeue = function() {
180 185
 };
181 186
 
182 187
 Client.prototype._handlePacket = function(packet) {
  188
+  if (this.debug) {
  189
+    this._debugPacket(packet);
  190
+  }
  191
+
183 192
   if (packet.type == Parser.GREETING_PACKET) {
184 193
     this._sendAuth(packet);
185 194
     return;
@@ -260,6 +269,21 @@ Client._packetToUserObject = function(packet) {
260 269
   delete packet.errorNumber;
261 270
 };
262 271
 
  272
+Client.prototype._debugPacket = function(packet) {
  273
+  var packetName = null;
  274
+  for (var key in Parser) {
  275
+    if (!key.match(/_PACKET$/)) {
  276
+      continue;
  277
+    }
  278
+
  279
+    if (Parser[key] == packet.type) {
  280
+      packetName = key;
  281
+      break;
  282
+    }
  283
+  }
  284
+  console.log('<- %s: %j', packetName, packet);
  285
+};
  286
+
263 287
 // Client Flags
264 288
 Client.LONG_PASSWORD     = 1;
265 289
 Client.FOUND_ROWS        = 2;
1  lib/mysql/parser.js
@@ -485,6 +485,7 @@ Parser.prototype.write = function(buffer) {
485 485
         if (packet.received == 1) {
486 486
           if (c === 0xfe) {
487 487
             packet.type = Parser.EOF_PACKET;
  488
+            this.receivingRowPackets = false;
488 489
             advance(Parser.EOF_WARNING_COUNT);
489 490
             break;
490 491
           }
2  package.json
... ...
@@ -1,5 +1,5 @@
1 1
 { "name" : "mysql"
2  
-, "version": "0.1.0"
  2
+, "version": "0.2.0"
3 3
 , "dependencies": {"gently": ">=0.8.0"}
4 4
 , "directories" : { "lib" : "./lib/mysql" }
5 5
 , "main" : "./lib/mysql/index"
2  test/simple/test-client.js
@@ -28,6 +28,8 @@ test(function constructor() {
28 28
       assert.strictEqual(client.password, null);
29 29
       assert.strictEqual(client.database, null);
30 30
 
  31
+      assert.strictEqual(client.debug, false);
  32
+
31 33
       assert.strictEqual(client.flags, Client.defaultFlags);
32 34
       assert.strictEqual(client.maxPacketSize, 0x01000000);
33 35
       assert.strictEqual(client.charsetNumber, 8);
1  test/simple/test-parser.js
@@ -343,5 +343,6 @@ test(function write() {
343 343
 
344 344
     parser.write(new Buffer([0xfe]));
345 345
     assert.equal(packet.type, Parser.EOF_PACKET);
  346
+    assert.equal(parser.receivingRowPackets, false);
346 347
   })();
347 348
 });
2  test/system/test-client-query-calculated-fields.js
@@ -10,7 +10,7 @@ client.connect();
10 10
 client.query('SELECT 1 as field_a, 2 as field_b', function(err, results) {
11 11
   if (err) throw err;
12 12
 
13  
-  console.log(results);
14 13
   assert.equal(results[0].field_a, 1);
15 14
   assert.equal(results[0].field_b, 2);
  15
+  client.end();
16 16
 });
22  test/system/test-client-sequential-query.js
... ...
@@ -0,0 +1,22 @@
  1
+require('../common');
  2
+var Client = require('mysql').Client,
  3
+    client = Client(TEST_CONFIG),
  4
+    gently = new Gently();
  5
+
  6
+// our test db might not exist yet, so don't try to connect to it
  7
+client.database = '';
  8
+client.connect();
  9
+
  10
+client.query('SELECT 1 as field_a, 2 as field_b', function(err, results) {
  11
+  if (err) throw err;
  12
+
  13
+  assert.equal(results[0].field_a, 1);
  14
+  assert.equal(results[0].field_b, 2);
  15
+});
  16
+
  17
+client.query('SELECT 3 as field_c', function(err, results) {
  18
+  if (err) throw err;
  19
+
  20
+  assert.equal(results[0].field_c, 3);
  21
+  client.end();
  22
+});

No commit comments for this range

Something went wrong with that request. Please try again.