From f69e82e7a6284625228d9f0e8b9ffa07eee19265 Mon Sep 17 00:00:00 2001 From: Basic Date: Thu, 18 Feb 2016 15:28:52 -0700 Subject: [PATCH 1/2] Changing tabs to spaces --- lib/databasemetadata.js | 14 +++++++------- lib/statement.js | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/databasemetadata.js b/lib/databasemetadata.js index 85e337f..8f8a6fe 100644 --- a/lib/databasemetadata.js +++ b/lib/databasemetadata.js @@ -19,13 +19,13 @@ function DatabaseMetaData(dbm) { * @returns {ResultSet} Via callback: a ResultSet object in which each row is a schema description */ DatabaseMetaData.prototype.getSchemas = function(catalog, schemaPattern, callback) { - if(_.isFunction(catalog)) { - callback = catalog; - catalog = null; - } else if(_.isFunction(schemaPattern)) { - callback = schemaPattern; - schemaPattern = null; - } + if(_.isFunction(catalog)) { + callback = catalog; + catalog = null; + } else if(_.isFunction(schemaPattern)) { + callback = schemaPattern; + schemaPattern = null; + } var validParams = ( (_.isNull(catalog) || _.isUndefined(catalog) || _.isString(catalog)) && diff --git a/lib/statement.js b/lib/statement.js index 859e71e..32edfe9 100644 --- a/lib/statement.js +++ b/lib/statement.js @@ -127,11 +127,11 @@ Statement.prototype.setQueryTimeout = function(seconds, callback) { Statement.prototype.getGeneratedKeys = function(callback) { this._s.getGeneratedKeys(function(err, resultset) { - if(err) { - return callback(err); - } + if(err) { + return callback(err); + } return callback(null, new ResultSet(resultset)); - }); + }); }; jinst.events.once('initialized', function onInitialized() { From ddeb381cc04ef551b6796cf99010c4b004313670 Mon Sep 17 00:00:00 2001 From: Basic Date: Thu, 18 Feb 2016 15:30:04 -0700 Subject: [PATCH 2/2] Solution for issue 94 - when returning int values, it should be returning null rather than zero for null integers --- lib/resultset.js | 50 +++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/lib/resultset.js b/lib/resultset.js index baaa49c..a7321cf 100644 --- a/lib/resultset.js +++ b/lib/resultset.js @@ -97,35 +97,33 @@ ResultSet.prototype.toObjectIter = function(callback) { rows: { next: function() { var nextRow = self._rs.nextSync(); - if (nextRow) { - var result = {}; - var type = 'String'; // Default to getStringSync getter. - - // loop through each column - _.each(_.range(1, colcount + 1), function(i) { - var cmd = colsmetadata[i-1]; - - if (self._types[cmd.type]) { - type = self._types[cmd.type]; - } else { - type = 'String'; // Default to getStringSync getter. - } + if (! nextRow) { + return {done: true}; + } - if (type === 'Date' || type === 'Time' || type === 'Timestamp') { - if (self._rs['get' + type + 'Sync'](i)) { - result[cmd.label] = self._rs['get' + type + 'Sync'](i).toString(); - } else { // if date is empty, it should be null - result[cmd.label] = null; - } - } else { - result[cmd.label] = self._rs['get' + type + 'Sync'](i); + var result = {}; + + // loop through each column + _.each(_.range(1, colcount + 1), function(i) { + var cmd = colsmetadata[i-1]; + var type = self._types[cmd.type] || 'String'; + var getter = 'get' + type + 'Sync'; + + if (type === 'Date' || type === 'Time' || type === 'Timestamp') { + var dateVal = self._rs[getter](i); + result[cmd.label] = dateVal ? dateVal.toString() : null; + } else { + // If the column is an integer and is null, set result to null and continue + if (type === 'Int' && _.isNull(self._rs.getObjectSync(i))) { + result[cmd.label] = null; + return; } - }); - return {value: result, done: false}; - } else { - return {done: true}; - } + result[cmd.label] = self._rs[getter](i); + } + }); + + return {value: result, done: false}; } } });