Skip to content

Commit 10e81c2

Browse files
mscdexfelixge
authored andcommitted
Fix to distinguish between NULL and empty string values.
Signed-off-by: Felix Geisendörfer <[email protected]>
1 parent 09df6f9 commit 10e81c2

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/mysql/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ Parser.prototype.write = function(buffer) {
494494

495495
packet.columnLength = lengthCoded(packet.columnLength);
496496
if (!packet.columnLength) {
497-
packet.emit('data', new Buffer(0), 0);
497+
packet.emit('data', (packet.columnLength === null ? null : new Buffer(0)), 0);
498498
if (packet.received < packet.length) {
499499
advance(Parser.COLUMN_VALUE_LENGTH);
500500
} else {

lib/mysql/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Query.prototype._handlePacket = function(packet) {
5353
row[field] = '';
5454

5555
packet.on('data', function(buffer, remaining) {
56-
if (buffer.length) {
56+
if (buffer) {
5757
row[field] += buffer;
5858
} else {
5959
row[field] = null;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+

0 commit comments

Comments
 (0)