Skip to content
This repository
  • 9 commits
  • 7 files changed
  • 2 comments
  • 3 contributors
10  Readme.md
Source Rendered
@@ -25,6 +25,10 @@ testing.
25 25
 
26 26
 [transloadit]: http://transloadit.com/
27 27
 
  28
+## Installation
  29
+
  30
+    npm install mysql
  31
+
28 32
 ## Design Goals
29 33
 
30 34
 * TDD: All code is written using test driven development, code coverage should approach 100%
@@ -93,7 +97,7 @@ testing.
93 97
 ### new mysql.Client([options])
94 98
 
95 99
 Creates a new client instance. Any client property can be set using the
96  
-`options array.
  100
+`options` object.
97 101
 
98 102
 ### client.host = 'localhost'
99 103
 
@@ -115,6 +119,10 @@ The password to use.
115 119
 
116 120
 The name of the database to connect to (optional).
117 121
 
  122
+### client.debug = false
  123
+
  124
+Prints incoming and outgoing packets, useful for development / testing purposes.
  125
+
118 126
 ### client.flags = Client.defaultFlags
119 127
 
120 128
 Connection flags send to the server.
11  lib/mysql/parser.js
@@ -493,6 +493,17 @@ Parser.prototype.write = function(buffer) {
493 493
         }
494 494
 
495 495
         packet.columnLength = lengthCoded(packet.columnLength);
  496
+
  497
+        if (!packet.columnLength && !this._lengthCodedLength) {
  498
+          packet.emit('data', (packet.columnLength === null ? null : new Buffer(0)), 0);
  499
+          if (packet.received < packet.length) {
  500
+            advance(Parser.COLUMN_VALUE_LENGTH);
  501
+          } else {
  502
+            self.packet = packet = null;
  503
+            self.state = state = Parser.PACKET_LENGTH;
  504
+            continue;
  505
+          }
  506
+        }
496 507
         break;
497 508
       case Parser.COLUMN_VALUE_STRING:
498 509
         var remaining = packet.columnLength - packet.index, read;
6  lib/mysql/query.js
@@ -53,7 +53,11 @@ Query.prototype._handlePacket = function(packet) {
53 53
       row[field] = '';
54 54
 
55 55
       packet.on('data', function(buffer, remaining) {
56  
-        row[field] += buffer;
  56
+        if (buffer) {
  57
+          row[field] += buffer;
  58
+        } else {
  59
+          row[field] = null;
  60
+        }
57 61
 
58 62
         if (remaining == 0) {
59 63
           self._rowIndex++;
5  package.json
... ...
@@ -1,6 +1,5 @@
1 1
 { "name" : "mysql"
2  
-, "version": "0.2.0"
  2
+, "version": "0.3.0"
3 3
 , "dependencies": {"gently": ">=0.8.0"}
4  
-, "directories" : { "lib" : "./lib/mysql" }
5  
-, "main" : "./lib/mysql/index"
  4
+, "main" : "./lib/mysql"
6 5
 }
16  test/system/test-client-query-empty.js
... ...
@@ -0,0 +1,16 @@
  1
+require('../common');
  2
+var Client = require('mysql').Client,
  3
+    client = Client(TEST_CONFIG),
  4
+    gently = new Gently();
  5
+
  6
+// our test db might not exist yet, so don't try to connect to it
  7
+client.database = '';
  8
+client.connect();
  9
+
  10
+client.query('SELECT "" as field_a', function(err, results) {
  11
+  if (err) throw err;
  12
+
  13
+  assert.strictEqual(results[0].field_a, "");
  14
+  client.end();
  15
+});
  16
+
42  test/system/test-client-query-long-fields.js
... ...
@@ -0,0 +1,42 @@
  1
+require('../common');
  2
+var Client = require('mysql').Client,
  3
+    client = Client(TEST_CONFIG),
  4
+    gently = new Gently();
  5
+
  6
+// our test db might not exist yet, so don't try to connect to it
  7
+client.connect();
  8
+
  9
+function makeString(length) {
  10
+  var str = '';
  11
+  for (var i = 0; i < length; i++) {
  12
+    str += 'x';
  13
+  }
  14
+  return str;
  15
+}
  16
+
  17
+var field_a = makeString(250),
  18
+    field_b = makeString(251),
  19
+    field_c = makeString(512),
  20
+    field_d = makeString(65537);
  21
+
  22
+function test(last) {
  23
+  var query = client.query(
  24
+    'SELECT ? as field_a, ? as field_b, ? as field_c, ? as field_d',
  25
+    [field_a, field_b, field_c, field_d],
  26
+    function(err, results) {
  27
+    if (err) throw err;
  28
+
  29
+    assert.equal(results[0].field_a, field_a);
  30
+    assert.equal(results[0].field_b, field_b);
  31
+    assert.equal(results[0].field_c, field_c);
  32
+    assert.equal(results[0].field_d, field_d);
  33
+    if (last) {
  34
+      client.end();
  35
+    }
  36
+  });
  37
+}
  38
+
  39
+// We execute this test twice to be sure the parser is in a good state after
  40
+// each run.
  41
+test();
  42
+test(true);
17  test/system/test-client-query-null.js
... ...
@@ -0,0 +1,17 @@
  1
+require('../common');
  2
+var Client = require('mysql').Client,
  3
+    client = Client(TEST_CONFIG),
  4
+    gently = new Gently();
  5
+
  6
+// our test db might not exist yet, so don't try to connect to it
  7
+client.database = '';
  8
+client.connect();
  9
+
  10
+client.query('SELECT NULL as field_a, NULL as field_b', function(err, results) {
  11
+  if (err) throw err;
  12
+
  13
+  assert.strictEqual(results[0].field_a, null);
  14
+  assert.strictEqual(results[0].field_b, null);
  15
+  client.end();
  16
+});
  17
+

Showing you all comments on commits in this comparison.

Bert Belder

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();
});

Felix Geisendörfer
Owner

Fixed in: 10e81c2

Something went wrong with that request. Please try again.