Skip to content

Commit

Permalink
Fix bad handling of null values
Browse files Browse the repository at this point in the history
Null values were causing problems in columns when typecasting them. This patch
makes sure null values are never typecasted.
  • Loading branch information
felixge committed Oct 29, 2010
1 parent 0bf10a7 commit a107dc6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mysql/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Query.prototype._handlePacket = function(packet) {

if (remaining == 0) {
self._rowIndex++;
if (self.typeCast) {
if (self.typeCast && buffer !== null) {
switch (field.fieldType) {
case Query.FIELD_TYPE_TIMESTAMP:
case Query.FIELD_TYPE_DATE:
Expand Down
5 changes: 3 additions & 2 deletions test/system/test-client-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ client.query(
var query = client.query(
'INSERT INTO '+TEST_TABLE+' '+
'SET title = ?, text = ?, created = ?',
['another entry', 'because 2 entries make a better test', '2010-08-16 12:42:15']
['another entry', 'because 2 entries make a better test', null]
);

query.on('end', gently.expect(function insertOkCb(packet) {
Expand All @@ -63,7 +63,8 @@ var query = client.query(
assert.equal(results.length, 2);
assert.equal(results[1].title, 'another entry');
assert.ok(typeof results[1].id == 'number');
assert.ok(results[1].created instanceof Date);
assert.ok(results[0].created instanceof Date);
assert.strictEqual(results[1].created, null);
client.end();
})
);

0 comments on commit a107dc6

Please sign in to comment.