Skip to content

Commit 5847ec8

Browse files
Dinwydougwilson
authored andcommitted
Fix type cast for BIGINT columns when number is negative
fixes #1376
1 parent e4d4084 commit 5847ec8

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ you spot any mistakes.
88

99
* Add `POOL_CONNLIMIT` code to "No connections available." error #1332
1010
* Fix Query stream to emit close after ending #1349 #1350
11+
* Fix type cast for BIGINT columns when number is negative #1376
1112
* Performance improvements for array/object escaping in SqlString #1331
1213
* Support Node.js 6.x
1314
* Update `bignumber.js` to 2.3.0

lib/protocol/packets/RowDataPacket.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function typeCast(field, parser, timeZone, supportBigNumbers, bigNumberStrings,
100100
numberString = parser.parseLengthCodedString();
101101
return (numberString === null || (field.zeroFill && numberString[0] == "0"))
102102
? numberString
103-
: ((supportBigNumbers && (bigNumberStrings || (Number(numberString) > IEEE_754_BINARY_64_PRECISION)))
103+
: ((supportBigNumbers && (bigNumberStrings || (Number(numberString) >= IEEE_754_BINARY_64_PRECISION) || Number(numberString) <= -IEEE_754_BINARY_64_PRECISION))
104104
? numberString
105105
: Number(numberString));
106106
case Types.BIT:

test/integration/connection/test-type-casting.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ var tests = [
1111
{type: 'double', insert: 5.5},
1212
{type: 'bigint', insert: '6', expect: 6},
1313
{type: 'bigint', insert: 6},
14+
{type: 'bigint', insert: '9007199254740991', expect: 9007199254740991},
15+
{type: 'bigint', insert: '9007199254740992', expect: '9007199254740992'},
16+
{type: 'bigint', insert: '9223372036854775807', expect: '9223372036854775807'},
17+
{type: 'bigint', insert: '-9007199254740991', expect: -9007199254740991},
18+
{type: 'bigint', insert: '-9007199254740992', expect: '-9007199254740992'},
19+
{type: 'bigint', insert: '-9223372036854775807', expect: '9223372036854775807'},
1420
{type: 'mediumint', insert: 7},
1521
{type: 'year', insert: 2012},
1622
{type: 'timestamp', insert: new Date('2012-05-12 11:00:23')},
@@ -52,7 +58,7 @@ var tests = [
5258

5359
var table = 'type_casting';
5460

55-
common.getTestConnection(function (err, connection) {
61+
common.getTestConnection({supportBigNumbers: true}, function (err, connection) {
5662
assert.ifError(err);
5763

5864
common.useTestDb(connection);

0 commit comments

Comments
 (0)