Skip to content

A bug fix for the Types.LONGLONG number range #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
2 changes: 1 addition & 1 deletion lib/protocol/packets/RowDataPacket.js
Original file line number Diff line number Diff line change
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
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
}, config);
}, config);
Copy link
Contributor

Choose a reason for hiding this comment

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

Needless whitespace change. This file should probably remain untouched in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How could I miss this. Thanks.


return config;
}
Expand Down
37 changes: 37 additions & 0 deletions test/integration/connection/test-query-bigint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var assert = require('assert');
var common = require('../../common');

var table = 'bigint_test';

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

common.useTestDb(connection);

connection.query([
'CREATE TEMPORARY TABLE ?? (',
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,',
'`big` bigint,',
'PRIMARY KEY (`id`)',
') ENGINE=InnoDB DEFAULT CHARSET=utf8'
].join('\n'), [table], assert.ifError);

connection.query('INSERT INTO ?? SET ?', [table, {big: '9223372036854775807'}]);
connection.query('INSERT INTO ?? SET ?', [table, {big: '-9223372036854775807'}]);
connection.query('INSERT INTO ?? SET ?', [table, {big: '1111111111111111111'}]);
connection.query('INSERT INTO ?? SET ?', [table, {big: '-1111111111111111111'}]);
connection.query('INSERT INTO ?? SET ?', [table, {big: '9007199254740993'}]);
connection.query('INSERT INTO ?? SET ?', [table, {big: '-9007199254740993'}]);

connection.query('SELECT * FROM ??', [table], function (err, rows) {
assert.ifError(err);
assert.equal(rows.length, 6);
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);
});
});