From 5e1183fa1b04d7f7cdb2a395bdf7a59275b01454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Thu, 2 Sep 2010 15:15:49 +0200 Subject: [PATCH 1/5] Add contributors to readme --- Readme.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Readme.md b/Readme.md index f0db7c586..34ddf5c6a 100644 --- a/Readme.md +++ b/Readme.md @@ -5,6 +5,13 @@ A node.js module implementing the [MySQL protocol](http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol). +## Contributors + +* Bert Belder ([piscisaureus](http://github.com/felixge/node-mysql/commits/master?author=piscisaureus)) +* Alan Gutierrez ([bigeasy](http://github.com/felixge/node-mysql/commits/master?author=bigeasy)) +* Brian ([mscdex](http://github.com/felixge/node-mysql/commits/master?author=mscdex)) +* Cal Henderson ([iamcal](http://github.com/felixge/node-mysql/commits/master?author=iamcal)) + ## Sponsors * [Joyent](http://www.joyent.com/) From ee63231c9231538161fed861e12cb5c315878bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Thu, 2 Sep 2010 15:37:03 +0200 Subject: [PATCH 2/5] Update todos --- Readme.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 34ddf5c6a..9247cfcd2 100644 --- a/Readme.md +++ b/Readme.md @@ -192,10 +192,9 @@ parameter is provided which contains the information from the mysql OK packet. At this point the module is ready to be tried out, but a lot of things are yet to be done: +* Auto-cast mysql types into JS types * Prepared Statements -* Test using no Password * Charsets handling -* Import Error code constants * ... ## License From 5e68d18e6b4f0ae6015a9b60598dcfcd9728cc09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 17 Sep 2010 09:46:07 +0200 Subject: [PATCH 3/5] Test case showing column ordering bug Original test case by Bert Belder: http://gist.github.com/583048 --- test/common.js | 1 + test/fixture/columnia.sql | 54 +++++++++++++++++++ test/system/test-client-query-column-order.js | 40 ++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 test/fixture/columnia.sql create mode 100644 test/system/test-client-query-column-order.js diff --git a/test/common.js b/test/common.js index cf91bdc8f..78becb9c7 100644 --- a/test/common.js +++ b/test/common.js @@ -12,6 +12,7 @@ global.TEST_CONFIG = { }; global.TEST_TABLE = 'posts'; +global.TEST_FIXTURES = path.join(__dirname, 'fixture'); global.Gently = require('gently'); global.assert = require('assert'); diff --git a/test/fixture/columnia.sql b/test/fixture/columnia.sql new file mode 100644 index 000000000..c770e4813 --- /dev/null +++ b/test/fixture/columnia.sql @@ -0,0 +1,54 @@ +CREATE TABLE `columnia` ( + `f0` bigint(20) unsigned NOT NULL DEFAULT '0', + `field0001` bigint(20) unsigned NOT NULL DEFAULT '0', + `field002` bigint(20) unsigned NOT NULL DEFAULT '0', + `field0000000003` bigint(20) unsigned DEFAULT NULL, + `field00004` bigint(20) unsigned NOT NULL DEFAULT '0', + `field000000000005` bigint(20) unsigned DEFAULT NULL, + `field0000000000006` bigint(20) unsigned NOT NULL, + `field000007` text NOT NULL, + `field0000000008` text NOT NULL, + `field009` int(10) NOT NULL DEFAULT '0', + `field00010` text NOT NULL, + `field000000000011` text NOT NULL, + `field00000012` text NOT NULL, + `field0000013` text NOT NULL, + `field00000000000014` text NOT NULL, + `field0000000015` text NOT NULL, + `field000016` text NOT NULL, + `field000000000017` text NOT NULL, + `field0000000000000018` text NOT NULL, + `field0000000000019` text NOT NULL, + `field0000000000020` text NOT NULL, + `field00000000000021` text NOT NULL, + `field00000000022` text NOT NULL, + `field000000000000000023` text NOT NULL, + `field000000000000024` text NOT NULL, + `field000000000000025` text NOT NULL, + `field0000000000000026` text NOT NULL, + `field0000000000027` text NOT NULL, + `field00000028` bigint(20) unsigned NOT NULL, + `field000000029` tinyint(1) NOT NULL, + `field000030` tinyint(1) NOT NULL DEFAULT '0', + `field31` text NOT NULL, + `field00000032` bigint(20) unsigned NOT NULL, + `fi33` int(11) NOT NULL DEFAULT '0', + `field00000034` bigint(20) unsigned DEFAULT NULL, + `field000035` text NOT NULL, + `field0036` int(11) NOT NULL DEFAULT '0', + `field0000000000000000000037` text NOT NULL, + `field0000000000000000000038` text NOT NULL, + `field0000000000000000000000000039` text NOT NULL, + `field0000000000000000040` text NOT NULL, + `field00000000000000000041` text NOT NULL, + `field00000000000000000000042` text NOT NULL, + `field00000000000000000043` text NOT NULL, + `field00000000000000000044` text NOT NULL, + `field00000000000000000000000045` text NOT NULL, + `field00000000000000046` text NOT NULL, + `field000000000000000047` text NOT NULL, + `field000000000000000000048` text NOT NULL, + `field49` text NOT NULL, + `field50` int(11) NOT NULL, + PRIMARY KEY (`f0`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 diff --git a/test/system/test-client-query-column-order.js b/test/system/test-client-query-column-order.js new file mode 100644 index 000000000..19161d947 --- /dev/null +++ b/test/system/test-client-query-column-order.js @@ -0,0 +1,40 @@ +require('../common'); +var REPEATS = 1000, + Client = require('mysql').Client, + client = Client(TEST_CONFIG), + fs = require('fs'), + gently = new Gently(); + +client.connect(); + +client.query('CREATE DATABASE '+TEST_DB, function(err) { + if (err && err.number != Client.ERROR_DB_CREATE_EXISTS) { + throw err; + } +}); +client.query('USE '+TEST_DB); + +client.query('DROP TABLE IF EXISTS columnia'); +var fixture = fs.readFileSync(TEST_FIXTURES+'/columnia.sql', 'utf8'); +client.query(fixture); + +var finished = 0; +for (var i = 0; i < REPEATS; i++) { + (function(i) { + var query = client.query("SHOW COLUMNS FROM columnia"); + + query.on('row', function(row) { + if (!row.Type) { + throw new Error('Column order mixed up after '+i+' queries.'); + } + }); + + query.on('end', function() { + finished++; + if (finished === REPEATS) { + process.exit(0); + } + }); + })(i); +} + From 734039465a438dc1fa3c15114a96652c745851aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 17 Sep 2010 10:04:13 +0200 Subject: [PATCH 4/5] Fix column ordering bug Original patch by Bert Belder, see: http://gist.github.com/583103 This patch also adds a unit test. I had to to move the packet.emit line a little, as to make the unit test easier to produce. --- lib/mysql/parser.js | 4 ++-- test/simple/test-parser.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mysql/parser.js b/lib/mysql/parser.js index 077a0e88f..078e867c5 100644 --- a/lib/mysql/parser.js +++ b/lib/mysql/parser.js @@ -515,10 +515,10 @@ Parser.prototype.write = function(buffer) { break; case Parser.COLUMN_VALUE_STRING: var remaining = packet.columnLength - packet.index, read; - if (i + remaining >= buffer.length) { + if (i + remaining > buffer.length) { read = buffer.length - i; - packet.emit('data', buffer.slice(i, buffer.length), remaining - read); packet.index += read; + packet.emit('data', buffer.slice(i, buffer.length), remaining - read); // the -1 offsets are because these values are also manipulated by the loop itself packet.received += read - 1; i = buffer.length; diff --git a/test/simple/test-parser.js b/test/simple/test-parser.js index 9ea60161d..f7bea4c28 100644 --- a/test/simple/test-parser.js +++ b/test/simple/test-parser.js @@ -343,6 +343,7 @@ test(function write() { assert.equal(event, 'data'); assert.equal(val.toString(), 'Fine!'); assert.equal(remaining, 0); + assert.equal(packet.index, 0); }); parser.write(new Buffer(' are you?\u0005Fine!')); From c05ecc888b1360ffdf8b6290d1db86462315e4fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 17 Sep 2010 10:05:36 +0200 Subject: [PATCH 5/5] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a990106c8..c8d78ac8c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name" : "mysql" -, "version": "0.4.0" +, "version": "0.5.0" , "dependencies": {"gently": ">=0.8.0"} , "main" : "./lib/mysql" }