Skip to content

Commit

Permalink
Fixed bigint out of range problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinwy committed Mar 30, 2016
1 parent 7588c28 commit fc77df8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions %HOMEDRIVE%%HOMEPATH%/.nvmw
Submodule .nvmw added at 80a504
9 changes: 5 additions & 4 deletions lib/protocol/packets/RowDataPacket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var Types = require('../constants/types');
var Charsets = require('../constants/charsets');
var Field = require('./Field');
var Types = require('../constants/types');
var Charsets = require('../constants/charsets');
var Field = require('./Field');
var IEEE_754_BINARY_64_PRECISION = Math.pow(2, 53);

module.exports = RowDataPacket;
function RowDataPacket() {
Expand Down Expand Up @@ -99,7 +100,7 @@ function typeCast(field, parser, timeZone, supportBigNumbers, bigNumberStrings,
numberString = parser.parseLengthCodedString();
return (numberString === null || (field.zeroFill && numberString[0] == "0"))
? numberString
: ((supportBigNumbers && (bigNumberStrings || (Number(numberString) > Number.MAX_SAFE_INTEGER || Number(numberString) < Number.MIN_SAFE_INTEGER)))
: ((supportBigNumbers && (bigNumberStrings || (Number(numberString) >= IEEE_754_BINARY_64_PRECISION) || (Number(numberString) <= -IEEE_754_BINARY_64_PRECISION)))
? numberString
: Number(numberString));
case Types.BIT:
Expand Down
2 changes: 1 addition & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function mergeTestConfig(config) {
port : process.env.MYSQL_PORT,
user : process.env.MYSQL_USER,
password : process.env.MYSQL_PASSWORD,
supportBigNumbers: true,
supportBigNumbers: true
}, config);

return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ common.getTestConnection(function (err, connection) {
connection.query('SELECT * FROM ??', [table], function (err, rows) {
assert.ifError(err);
assert.equal(rows.length, 6);
assert.strictEqual(rows[0].big.toString(), '9223372036854775807');
assert.strictEqual(rows[1].big.toString(), '-9223372036854775807');
assert.strictEqual(rows[2].big.toString(), '1111111111111111111');
assert.strictEqual(rows[3].big.toString(), '-1111111111111111111');
assert.strictEqual(rows[4].big.toString(), '9007199254740993');
assert.strictEqual(rows[5].big.toString(), '-9007199254740993');
assert.strictEqual(rows[0].big, '9223372036854775807');
assert.strictEqual(rows[1].big, '-9223372036854775807');
assert.strictEqual(rows[2].big, '1111111111111111111');
assert.strictEqual(rows[3].big, '-1111111111111111111');
assert.strictEqual(rows[4].big, '9007199254740993');
assert.strictEqual(rows[5].big, '-9007199254740993');
connection.end(assert.ifError);
});
});

0 comments on commit fc77df8

Please sign in to comment.