From d54a27d9ef4cbdb3c631d565c69b4588fb6e881f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 22 Aug 2010 21:09:25 +0200 Subject: [PATCH 1/9] Add npm install hint to readme --- Readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Readme.md b/Readme.md index bf5d21df6..855ef9099 100644 --- a/Readme.md +++ b/Readme.md @@ -25,6 +25,10 @@ testing. [transloadit]: http://transloadit.com/ +## Installation + + npm install mysql + ## Design Goals * TDD: All code is written using test driven development, code coverage should approach 100% From 79c7b137663d18177014ecb2bbd0edea8b7602e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 22 Aug 2010 21:34:00 +0200 Subject: [PATCH 2/9] Docs typo --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 855ef9099..fe0819fbd 100644 --- a/Readme.md +++ b/Readme.md @@ -97,7 +97,7 @@ testing. ### new mysql.Client([options]) Creates a new client instance. Any client property can be set using the -`options array. +`options` array. ### client.host = 'localhost' From 9633f0d415001357fa655bb95f010a8a863468bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 22 Aug 2010 21:35:05 +0200 Subject: [PATCH 3/9] Document debug mode --- Readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Readme.md b/Readme.md index fe0819fbd..9873efcdd 100644 --- a/Readme.md +++ b/Readme.md @@ -119,6 +119,10 @@ The password to use. The name of the database to connect to (optional). +### client.debug = false + +Prints incoming and outgoing packets, useful for development / testing purposes. + ### client.flags = Client.defaultFlags Connection flags send to the server. From 4a930561e9b8fc0c5bce48fe477cd73ac67b8401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 22 Aug 2010 21:49:04 +0200 Subject: [PATCH 4/9] Readme fix --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 9873efcdd..f0db7c586 100644 --- a/Readme.md +++ b/Readme.md @@ -97,7 +97,7 @@ testing. ### new mysql.Client([options]) Creates a new client instance. Any client property can be set using the -`options` array. +`options` object. ### client.host = 'localhost' From 09df6f99dfa7e874a89ecf0115a2c40890d64f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 22 Aug 2010 23:00:26 +0200 Subject: [PATCH 5/9] Handle null-values properly --- lib/mysql/parser.js | 10 ++++++++++ lib/mysql/query.js | 6 +++++- test/system/test-client-query-null.js | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/system/test-client-query-null.js diff --git a/lib/mysql/parser.js b/lib/mysql/parser.js index 68d386c09..42d2b14f3 100644 --- a/lib/mysql/parser.js +++ b/lib/mysql/parser.js @@ -493,6 +493,16 @@ Parser.prototype.write = function(buffer) { } packet.columnLength = lengthCoded(packet.columnLength); + if (!packet.columnLength) { + packet.emit('data', new Buffer(0), 0); + if (packet.received < packet.length) { + advance(Parser.COLUMN_VALUE_LENGTH); + } else { + self.packet = packet = null; + self.state = state = Parser.PACKET_LENGTH; + continue; + } + } break; case Parser.COLUMN_VALUE_STRING: var remaining = packet.columnLength - packet.index, read; diff --git a/lib/mysql/query.js b/lib/mysql/query.js index f5a6d7677..a1253f86e 100644 --- a/lib/mysql/query.js +++ b/lib/mysql/query.js @@ -53,7 +53,11 @@ Query.prototype._handlePacket = function(packet) { row[field] = ''; packet.on('data', function(buffer, remaining) { - row[field] += buffer; + if (buffer.length) { + row[field] += buffer; + } else { + row[field] = null; + } if (remaining == 0) { self._rowIndex++; diff --git a/test/system/test-client-query-null.js b/test/system/test-client-query-null.js new file mode 100644 index 000000000..4d672673e --- /dev/null +++ b/test/system/test-client-query-null.js @@ -0,0 +1,17 @@ +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.query('SELECT NULL as field_a, NULL as field_b', function(err, results) { + if (err) throw err; + + assert.strictEqual(results[0].field_a, null); + assert.strictEqual(results[0].field_b, null); + client.end(); +}); + From 10e81c252e6a9f3d83e9d05a8e8f693a2756784c Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 23 Aug 2010 07:26:24 -0400 Subject: [PATCH 6/9] Fix to distinguish between NULL and empty string values. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Felix Geisendörfer --- lib/mysql/parser.js | 2 +- lib/mysql/query.js | 2 +- test/system/test-client-query-empty.js | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/system/test-client-query-empty.js diff --git a/lib/mysql/parser.js b/lib/mysql/parser.js index 42d2b14f3..6be55832c 100644 --- a/lib/mysql/parser.js +++ b/lib/mysql/parser.js @@ -494,7 +494,7 @@ Parser.prototype.write = function(buffer) { packet.columnLength = lengthCoded(packet.columnLength); if (!packet.columnLength) { - packet.emit('data', new Buffer(0), 0); + packet.emit('data', (packet.columnLength === null ? null : new Buffer(0)), 0); if (packet.received < packet.length) { advance(Parser.COLUMN_VALUE_LENGTH); } else { diff --git a/lib/mysql/query.js b/lib/mysql/query.js index a1253f86e..dec386f07 100644 --- a/lib/mysql/query.js +++ b/lib/mysql/query.js @@ -53,7 +53,7 @@ Query.prototype._handlePacket = function(packet) { row[field] = ''; packet.on('data', function(buffer, remaining) { - if (buffer.length) { + if (buffer) { row[field] += buffer; } else { row[field] = null; diff --git a/test/system/test-client-query-empty.js b/test/system/test-client-query-empty.js new file mode 100644 index 000000000..cb99062be --- /dev/null +++ b/test/system/test-client-query-empty.js @@ -0,0 +1,16 @@ +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.query('SELECT "" as field_a', function(err, results) { + if (err) throw err; + + assert.strictEqual(results[0].field_a, ""); + client.end(); +}); + From 97853a4ced8c77781886ade1041794c38d988137 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 24 Aug 2010 18:49:34 +0800 Subject: [PATCH 7/9] package.json update. --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index b536615f0..101ef0785 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name" : "mysql" , "version": "0.2.0" , "dependencies": {"gently": ">=0.8.0"} -, "directories" : { "lib" : "./lib/mysql" } -, "main" : "./lib/mysql/index" +, "main" : "./lib/mysql" } From f0ce2e368288175e5c06f8f94f9c6983741084fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Wed, 25 Aug 2010 11:35:13 +0200 Subject: [PATCH 8/9] Fix parsing long field values Fields with > 250 characters were causing problems. See: http://github.com/felixge/node-mysql/issues#issue/7 http://github.com/felixge/node-mysql/issues#issue/8 --- lib/mysql/parser.js | 3 +- test/system/test-client-query-long-fields.js | 42 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/system/test-client-query-long-fields.js diff --git a/lib/mysql/parser.js b/lib/mysql/parser.js index 6be55832c..0ab523585 100644 --- a/lib/mysql/parser.js +++ b/lib/mysql/parser.js @@ -493,7 +493,8 @@ Parser.prototype.write = function(buffer) { } packet.columnLength = lengthCoded(packet.columnLength); - if (!packet.columnLength) { + + if (!packet.columnLength && !this._lengthCodedLength) { packet.emit('data', (packet.columnLength === null ? null : new Buffer(0)), 0); if (packet.received < packet.length) { advance(Parser.COLUMN_VALUE_LENGTH); diff --git a/test/system/test-client-query-long-fields.js b/test/system/test-client-query-long-fields.js new file mode 100644 index 000000000..8486d22e9 --- /dev/null +++ b/test/system/test-client-query-long-fields.js @@ -0,0 +1,42 @@ +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.connect(); + +function makeString(length) { + var str = ''; + for (var i = 0; i < length; i++) { + str += 'x'; + } + return str; +} + +var field_a = makeString(250), + field_b = makeString(251), + field_c = makeString(512), + field_d = makeString(65537); + +function test(last) { + var query = client.query( + 'SELECT ? as field_a, ? as field_b, ? as field_c, ? as field_d', + [field_a, field_b, field_c, field_d], + function(err, results) { + if (err) throw err; + + assert.equal(results[0].field_a, field_a); + assert.equal(results[0].field_b, field_b); + assert.equal(results[0].field_c, field_c); + assert.equal(results[0].field_d, field_d); + if (last) { + client.end(); + } + }); +} + +// We execute this test twice to be sure the parser is in a good state after +// each run. +test(); +test(true); From 3406bc68044d3ac5b360b854420bc3e49892ef1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Wed, 25 Aug 2010 13:35:51 +0200 Subject: [PATCH 9/9] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 101ef0785..35f588028 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name" : "mysql" -, "version": "0.2.0" +, "version": "0.3.0" , "dependencies": {"gently": ">=0.8.0"} , "main" : "./lib/mysql" }