Skip to content

Commit

Permalink
java type mappings, logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Ozias committed Apr 17, 2016
1 parent a2c588c commit e9bd17c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
43 changes: 22 additions & 21 deletions lib/preparedstatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var ResultSet = require('./resultset');
var ResultSetMetaData = require('./resultsetmetadata');
var Statement = require('./statement');
var winston = require('winston');

function PreparedStatement(ps) {
Statement.call(this, ps);
Expand All @@ -14,42 +15,42 @@ PreparedStatement.prototype.constructor = PreparedStatement;

PreparedStatement.prototype.addBatch = function(callback) {
this._ps.addBatch(function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};

PreparedStatement.prototype.clearParameters = function(callback) {
this._ps.clearParameters(function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};

PreparedStatement.prototype.execute = function(callback) {
this._ps.execute(function(err, result) {
if (err) callback(err);
if (err) { winston.error(err); return callback(err); }
callback(null, result);
});
};

PreparedStatement.prototype.executeQuery = function(callback) {
this._ps.executeQuery(function(err, resultset) {
if (err) callback(err);
if (err) { winston.error(err); return callback(err); }
callback(null, new ResultSet(resultset));
});
};

PreparedStatement.prototype.executeUpdate = function(callback) {
this._ps.executeUpdate(function(err, result) {
if (err) callback(err);
if (err) { winston.error(err); return callback(err); }
callback(null, result);
});
};

PreparedStatement.prototype.getMetaData = function(callback) {
this._ps.getMetaData(function(err, result) {
if (err) callback(err);
if (err) return callback(err);
callback(null, new ResultSetMetaData(result));
});
};
Expand All @@ -74,7 +75,7 @@ PreparedStatement.prototype.setAsciiStream = function(index, val, length, callba
// val must be a java.math.BigDecimal
PreparedStatement.prototype.setBigDecimal = function(index, val, callback) {
this._ps.setBigDecimal(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};
Expand All @@ -93,21 +94,21 @@ PreparedStatement.prototype.setBlob = function(index, val, length, callback) {

PreparedStatement.prototype.setBoolean = function(index, val, callback) {
this._ps.setBoolean(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};

PreparedStatement.prototype.setByte = function(index, val, callback) {
this._ps.setByte(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};

PreparedStatement.prototype.setBytes = function(index, val, callback) {
this._ps.setBytes(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};
Expand All @@ -127,61 +128,61 @@ PreparedStatement.prototype.setClob = function(index, val, length, callback) {
PreparedStatement.prototype.setDate = function(index, val, calendar, callback) {
if (calendar == null) {
this._ps.setDate(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
} else {
this._ps.setDate(index, val, calendar, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
}
};

PreparedStatement.prototype.setDouble = function(index, val, callback) {
this._ps.setDouble(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};

PreparedStatement.prototype.setFloat = function(index, val, callback) {
this._ps.setFloat(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};

PreparedStatement.prototype.setInt = function(index, val, callback) {
this._ps.setInt(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};

PreparedStatement.prototype.setLong = function(index, val, callback) {
this._ps.setLong(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};

PreparedStatement.prototype.setString = function(index, val, callback) {
this._ps.setString(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
};

PreparedStatement.prototype.setTime = function(index, val, calendar, callback) {
if (calendar == null) {
this._ps.setTime(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
} else {
this._ps.setTime(index, val, calendar, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
}
Expand All @@ -190,12 +191,12 @@ PreparedStatement.prototype.setTime = function(index, val, calendar, callback) {
PreparedStatement.prototype.setTimestamp = function(index, val, calendar, callback) {
if (calendar == null) {
this._ps.setTimestamp(index, val, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
} else {
this._ps.setTimestamp(index, val, calendar, function(err) {
if (err) callback(err);
if (err) return callback(err);
callback(null);
});
}
Expand Down
14 changes: 9 additions & 5 deletions lib/resultset.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var _ = require('lodash');
var jinst = require('./jinst');
var ResultSetMetaData = require('./resultsetmetadata');
var java = jinst.getInstance();
var winston = require('winston');

if (!jinst.isJvmCreated()) {
jinst.addOption("-Xrs");
Expand All @@ -22,15 +23,16 @@ function ResultSet(rs) {
this._types = (function() {
var typeNames = [];

typeNames[java.getStaticFieldValue("java.sql.Types", "TINYINT")] = "Int";
typeNames[java.getStaticFieldValue("java.sql.Types", "SMALLINT")] = "Int";
typeNames[java.getStaticFieldValue("java.sql.Types", "BIT")] = "Boolean";
typeNames[java.getStaticFieldValue("java.sql.Types", "TINYINT")] = "Short";
typeNames[java.getStaticFieldValue("java.sql.Types", "SMALLINT")] = "Short";
typeNames[java.getStaticFieldValue("java.sql.Types", "INTEGER")] = "Int";
typeNames[java.getStaticFieldValue("java.sql.Types", "BIGINT")] = "String";
typeNames[java.getStaticFieldValue("java.sql.Types", "BIGINT")] = "Long";
typeNames[java.getStaticFieldValue("java.sql.Types", "FLOAT")] = "Float";
typeNames[java.getStaticFieldValue("java.sql.Types", "REAL")] = "Float";
typeNames[java.getStaticFieldValue("java.sql.Types", "DOUBLE")] = "Double";
typeNames[java.getStaticFieldValue("java.sql.Types", "NUMERIC")] = "Float";
typeNames[java.getStaticFieldValue("java.sql.Types", "DECIMAL")] = "Float";
typeNames[java.getStaticFieldValue("java.sql.Types", "NUMERIC")] = "BigDecimal";
typeNames[java.getStaticFieldValue("java.sql.Types", "DECIMAL")] = "BigDecimal";
typeNames[java.getStaticFieldValue("java.sql.Types", "CHAR")] = "String";
typeNames[java.getStaticFieldValue("java.sql.Types", "VARCHAR")] = "String";
typeNames[java.getStaticFieldValue("java.sql.Types", "LONGVARCHAR")] = "String";
Expand All @@ -41,6 +43,8 @@ function ResultSet(rs) {
typeNames[java.getStaticFieldValue("java.sql.Types", "NCHAR")] = "String";
typeNames[java.getStaticFieldValue("java.sql.Types", "NVARCHAR")] = "String";
typeNames[java.getStaticFieldValue("java.sql.Types", "LONGNVARCHAR")] = "String";
typeNames[java.getStaticFieldValue("java.sql.Types", "BINARY")] = "Bytes";
typeNames[java.getStaticFieldValue("java.sql.Types", "VARBINARY")] = "Bytes";
typeNames[java.getStaticFieldValue("java.sql.Types", "LONGVARBINARY")] = "Bytes";
typeNames[java.getStaticFieldValue("java.sql.Types", "BLOB")] = "Bytes";

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jdbc",
"version": "0.2.3-pre.0",
"version": "0.2.3-pre.8",
"description": "Node Module JDBC wrapper",
"main": "index.js",
"dependencies": {
Expand Down

2 comments on commit e9bd17c

@coretechs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BIGINT columns are not working properly again. I previously commented on the truncation problems here:

#63

Since you are now using java.math.BigDecimal for NUMERIC & DECIMAL I suggest java.math.BigInteger for BIGINT (or String).

@CraZySacX
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, forgot about the truncation of Long. I'll get this fixed shortly.

Please sign in to comment.