From 1072c1b44e2ebb2cd0d66231767197b423b5d3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 22 Aug 2010 20:45:57 +0200 Subject: [PATCH 1/4] Add a basic debug mode --- lib/mysql/client.js | 24 +++++++++++++++++++ test/simple/test-client.js | 2 ++ .../test-client-query-calculated-fields.js | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/mysql/client.js b/lib/mysql/client.js index e0f619978..b609377f0 100644 --- a/lib/mysql/client.js +++ b/lib/mysql/client.js @@ -24,6 +24,7 @@ function Client(config) { this.flags = Client.defaultFlags; this.maxPacketSize = 0x01000000; this.charsetNumber = 8; + this.debug = false; this._queue = []; this._connection = null; @@ -113,6 +114,10 @@ Client.prototype.query = function(sql, params, cb) { }; Client.prototype.write = function(packet) { + if (this.debug) { + console.log('-> %s', packet.buffer.inspect()); + } + this._connection.write(packet.buffer); }; @@ -180,6 +185,10 @@ Client.prototype._dequeue = function() { }; Client.prototype._handlePacket = function(packet) { + if (this.debug) { + this._debugPacket(packet); + } + if (packet.type == Parser.GREETING_PACKET) { this._sendAuth(packet); return; @@ -260,6 +269,21 @@ Client._packetToUserObject = function(packet) { delete packet.errorNumber; }; +Client.prototype._debugPacket = function(packet) { + var packetName = null; + for (var key in Parser) { + if (!key.match(/_PACKET$/)) { + continue; + } + + if (Parser[key] == packet.type) { + packetName = key; + break; + } + } + console.log('<- %s: %j', packetName, packet); +}; + // Client Flags Client.LONG_PASSWORD = 1; Client.FOUND_ROWS = 2; diff --git a/test/simple/test-client.js b/test/simple/test-client.js index b385b7d78..a0d858ac4 100644 --- a/test/simple/test-client.js +++ b/test/simple/test-client.js @@ -28,6 +28,8 @@ test(function constructor() { assert.strictEqual(client.password, null); assert.strictEqual(client.database, null); + assert.strictEqual(client.debug, false); + assert.strictEqual(client.flags, Client.defaultFlags); assert.strictEqual(client.maxPacketSize, 0x01000000); assert.strictEqual(client.charsetNumber, 8); diff --git a/test/system/test-client-query-calculated-fields.js b/test/system/test-client-query-calculated-fields.js index 314107f1b..b40f6a7bc 100644 --- a/test/system/test-client-query-calculated-fields.js +++ b/test/system/test-client-query-calculated-fields.js @@ -10,7 +10,7 @@ client.connect(); client.query('SELECT 1 as field_a, 2 as field_b', function(err, results) { if (err) throw err; - console.log(results); assert.equal(results[0].field_a, 1); assert.equal(results[0].field_b, 2); + client.end(); }); From 1f36260d4ba8c698944f1b6bdf9349a818631c2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 22 Aug 2010 20:49:26 +0200 Subject: [PATCH 2/4] Add failing sequential query test --- test/system/test-client-sequential-query.js | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test/system/test-client-sequential-query.js diff --git a/test/system/test-client-sequential-query.js b/test/system/test-client-sequential-query.js new file mode 100644 index 000000000..c848a7bad --- /dev/null +++ b/test/system/test-client-sequential-query.js @@ -0,0 +1,24 @@ +require('../common'); +var Client = require('mysql').Client, + client = Client(TEST_CONFIG), + gently = new Gently(); + +// our test db might not exist yet, so don't try to connect to it +client.database = ''; +client.connect(); + +client.debug = true; + +client.query('SELECT 1 as field_a, 2 as field_b', function(err, results) { + if (err) throw err; + + assert.equal(results[0].field_a, 1); + assert.equal(results[0].field_b, 2); +}); + +client.query('SELECT 3 as field_c', function(err, results) { + if (err) throw err; + + assert.equal(results[0].field_c, 3); + client.end(); +}); From 94ce814182bcdb956a84e1d220551c413f5c15e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 22 Aug 2010 21:05:51 +0200 Subject: [PATCH 3/4] 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 --- lib/mysql/parser.js | 1 + test/simple/test-parser.js | 1 + test/system/test-client-sequential-query.js | 2 -- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mysql/parser.js b/lib/mysql/parser.js index 4834484be..68d386c09 100644 --- a/lib/mysql/parser.js +++ b/lib/mysql/parser.js @@ -485,6 +485,7 @@ Parser.prototype.write = function(buffer) { if (packet.received == 1) { if (c === 0xfe) { packet.type = Parser.EOF_PACKET; + this.receivingRowPackets = false; advance(Parser.EOF_WARNING_COUNT); break; } diff --git a/test/simple/test-parser.js b/test/simple/test-parser.js index 5d44dfd64..ccdc9d00e 100644 --- a/test/simple/test-parser.js +++ b/test/simple/test-parser.js @@ -343,5 +343,6 @@ test(function write() { parser.write(new Buffer([0xfe])); assert.equal(packet.type, Parser.EOF_PACKET); + assert.equal(parser.receivingRowPackets, false); })(); }); diff --git a/test/system/test-client-sequential-query.js b/test/system/test-client-sequential-query.js index c848a7bad..b5049a06a 100644 --- a/test/system/test-client-sequential-query.js +++ b/test/system/test-client-sequential-query.js @@ -7,8 +7,6 @@ var Client = require('mysql').Client, client.database = ''; client.connect(); -client.debug = true; - client.query('SELECT 1 as field_a, 2 as field_b', function(err, results) { if (err) throw err; From d668f10d8af11441fffdf70151353fb6d45bf6a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 22 Aug 2010 21:07:41 +0200 Subject: [PATCH 4/4] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 92666b6f5..b536615f0 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name" : "mysql" -, "version": "0.1.0" +, "version": "0.2.0" , "dependencies": {"gently": ">=0.8.0"} , "directories" : { "lib" : "./lib/mysql" } , "main" : "./lib/mysql/index" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy