Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: felixge/node-mysql
...
head fork: felixge/node-mysql
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 7 files changed
  • 2 commit comments
  • 3 contributors
View
10 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.
View
11 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;
View
6 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++;
View
5 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"
}
View
16 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();
+});
+
View
42 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);
View
17 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();
+});
+

Showing you all comments on commits in this comparison.

@piscisaureus

This doesn't handle null values; now there is no distinction between null and the empty string. Try:

client.query('SELECT NULL as field_a, NULL as field_b, "" AS field_c', function(err, results) {
if (err) throw err;

assert.strictEqual(results[0].field_a, null);
assert.strictEqual(results[0].field_b, null);
assert.strictEqual(results[0].field_c, '');
client.end();
});

@felixge
Owner

Fixed in: 10e81c2

Something went wrong with that request. Please try again.