Skip to content

Commit

Permalink
Fix type cast for BIGINT columns when number is negative
Browse files Browse the repository at this point in the history
fixes #1376
  • Loading branch information
Dinwy authored and dougwilson committed May 8, 2016
1 parent e4d4084 commit 5847ec8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -8,6 +8,7 @@ you spot any mistakes.

* Add `POOL_CONNLIMIT` code to "No connections available." error #1332
* Fix Query stream to emit close after ending #1349 #1350
* Fix type cast for BIGINT columns when number is negative #1376
* Performance improvements for array/object escaping in SqlString #1331
* Support Node.js 6.x
* Update `bignumber.js` to 2.3.0
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/packets/RowDataPacket.js
Expand Up @@ -100,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) > IEEE_754_BINARY_64_PRECISION)))
: ((supportBigNumbers && (bigNumberStrings || (Number(numberString) >= IEEE_754_BINARY_64_PRECISION) || Number(numberString) <= -IEEE_754_BINARY_64_PRECISION))
? numberString
: Number(numberString));
case Types.BIT:
Expand Down
8 changes: 7 additions & 1 deletion test/integration/connection/test-type-casting.js
Expand Up @@ -11,6 +11,12 @@ var tests = [
{type: 'double', insert: 5.5},
{type: 'bigint', insert: '6', expect: 6},
{type: 'bigint', insert: 6},
{type: 'bigint', insert: '9007199254740991', expect: 9007199254740991},
{type: 'bigint', insert: '9007199254740992', expect: '9007199254740992'},
{type: 'bigint', insert: '9223372036854775807', expect: '9223372036854775807'},
{type: 'bigint', insert: '-9007199254740991', expect: -9007199254740991},
{type: 'bigint', insert: '-9007199254740992', expect: '-9007199254740992'},
{type: 'bigint', insert: '-9223372036854775807', expect: '9223372036854775807'},
{type: 'mediumint', insert: 7},
{type: 'year', insert: 2012},
{type: 'timestamp', insert: new Date('2012-05-12 11:00:23')},
Expand Down Expand Up @@ -52,7 +58,7 @@ var tests = [

var table = 'type_casting';

common.getTestConnection(function (err, connection) {
common.getTestConnection({supportBigNumbers: true}, function (err, connection) {
assert.ifError(err);

common.useTestDb(connection);
Expand Down

0 comments on commit 5847ec8

Please sign in to comment.