Skip to content

Commit

Permalink
Merge pull request #95 from dash-/feature-94
Browse files Browse the repository at this point in the history
Feature 94 - Solution to Issue #94
  • Loading branch information
CraZySacX committed Feb 22, 2016
2 parents c851658 + ddeb381 commit b8cae64
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
14 changes: 7 additions & 7 deletions lib/databasemetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) &&
Expand Down
50 changes: 24 additions & 26 deletions lib/resultset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
}
});
Expand Down
8 changes: 4 additions & 4 deletions lib/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit b8cae64

Please sign in to comment.