Skip to content

Commit a43e8da

Browse files
authored
Merge pull request #681 from sidorares/null-buffer
Add support for NULL to readLengthCodedBuffer. Fixes #668
2 parents 97a8853 + 0059e66 commit a43e8da

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

lib/packets/packet.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ Packet.prototype.readInt64 = function() {
117117
var word0 = this.readInt32();
118118
var word1 = this.readInt32();
119119
var res = new Long(word0, word1, true);
120-
var resNumber = res.toNumber(),
121-
resString = res.toString();
120+
var resNumber = res.toNumber(), resString = res.toString();
122121

123122
res = resNumber.toString() === resString ? resNumber : resString;
124123

@@ -129,8 +128,7 @@ Packet.prototype.readSInt64 = function() {
129128
var word0 = this.readInt32();
130129
var word1 = this.readInt32();
131130
var res = new Long(word0, word1, false);
132-
var resNumber = res.toNumber(),
133-
resString = res.toString();
131+
var resNumber = res.toNumber(), resString = res.toString();
134132

135133
res = resNumber.toString() === resString ? resNumber : resString;
136134

@@ -196,8 +194,7 @@ Packet.prototype.readLengthCodedNumberExt = function(
196194

197195
res = new Long(word0, word1, !signed); // Long need unsigned
198196

199-
var resNumber = res.toNumber(),
200-
resString = res.toString();
197+
var resNumber = res.toNumber(), resString = res.toString();
201198

202199
res = resNumber.toString() === resString ? resNumber : resString;
203200

@@ -369,6 +366,9 @@ Packet.prototype.readLengthCodedString = function(encoding) {
369366

370367
Packet.prototype.readLengthCodedBuffer = function() {
371368
var len = this.readLengthCodedNumber();
369+
if (len === null) {
370+
return null;
371+
}
372372
return this.readBuffer(len);
373373
};
374374

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var common = require('../../common');
2+
var connection = common.createConnection();
3+
var assert = require('assert');
4+
5+
var rowsTextProtocol;
6+
var rowsBinaryProtocol;
7+
8+
connection.query('CREATE TEMPORARY TABLE binary_table (stuff BINARY(16));');
9+
connection.query('INSERT INTO binary_table VALUES(null)');
10+
11+
connection.query('SELECT * from binary_table', function(err, _rows) {
12+
if (err) {
13+
throw err;
14+
}
15+
rowsTextProtocol = _rows;
16+
connection.execute('SELECT * from binary_table', function(
17+
err,
18+
_rows,
19+
_fields
20+
) {
21+
if (err) {
22+
throw err;
23+
}
24+
rowsBinaryProtocol = _rows;
25+
connection.end();
26+
});
27+
});
28+
29+
process.on('exit', function() {
30+
assert.deepEqual(rowsTextProtocol[0], { stuff: null });
31+
assert.deepEqual(rowsBinaryProtocol[0], { stuff: null });
32+
});

0 commit comments

Comments
 (0)