Skip to content

Commit

Permalink
Fix to distinguish between NULL and empty string values.
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Geisendörfer <felix@debuggable.com>
  • Loading branch information
mscdex authored and felixge committed Aug 23, 2010
1 parent 09df6f9 commit 10e81c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/mysql/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ Parser.prototype.write = function(buffer) {

packet.columnLength = lengthCoded(packet.columnLength);
if (!packet.columnLength) {
packet.emit('data', new Buffer(0), 0);
packet.emit('data', (packet.columnLength === null ? null : new Buffer(0)), 0);
if (packet.received < packet.length) {
advance(Parser.COLUMN_VALUE_LENGTH);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/mysql/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Query.prototype._handlePacket = function(packet) {
row[field] = '';

packet.on('data', function(buffer, remaining) {
if (buffer.length) {
if (buffer) {
row[field] += buffer;
} else {
row[field] = null;
Expand Down
16 changes: 16 additions & 0 deletions test/system/test-client-query-empty.js
Original file line number Diff line number Diff line change
@@ -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();
});

0 comments on commit 10e81c2

Please sign in to comment.