diff --git a/Readme.md b/Readme.md index bf5d21df6..f0db7c586 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% @@ -93,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' @@ -115,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. diff --git a/lib/mysql/parser.js b/lib/mysql/parser.js index 68d386c09..0ab523585 100644 --- a/lib/mysql/parser.js +++ b/lib/mysql/parser.js @@ -493,6 +493,17 @@ Parser.prototype.write = function(buffer) { } packet.columnLength = lengthCoded(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); + } 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..dec386f07 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) { + row[field] += buffer; + } else { + row[field] = null; + } if (remaining == 0) { self._rowIndex++; diff --git a/package.json b/package.json index b536615f0..35f588028 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name" : "mysql" -, "version": "0.2.0" +, "version": "0.3.0" , "dependencies": {"gently": ">=0.8.0"} -, "directories" : { "lib" : "./lib/mysql" } -, "main" : "./lib/mysql/index" +, "main" : "./lib/mysql" } 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(); +}); + 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); 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(); +}); + 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