From 9b7d35593f130ab65fa90ad4b91c5590a9bf5720 Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 30 Mar 2016 02:06:50 +0900 Subject: [PATCH 01/12] A bug fix for the Types.LONGLONG number range According to MDN(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#Integer_range_for_Number), Integer range for Number is -9007199254740992 to 9007199254740992. But In the original code, 1. There is no range for the negative value. 2. Can't print out 9007199254740993 value. Because of the gt sign at line 103 : Number(numberString) > IEEE_754_BINARY_64_PRECISION. --- lib/protocol/packets/RowDataPacket.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index 0912ce047..cd091c765 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -1,7 +1,6 @@ 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() { @@ -100,7 +99,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) > Number.MAX_SAFE_INTEGER || Number(numberString) < Number.MIN_SAFE_INTEGER))) ? numberString : Number(numberString)); case Types.BIT: From c012136011044748c4bbfe4c19ec54ff99e3d2c5 Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 30 Mar 2016 02:32:34 +0900 Subject: [PATCH 02/12] Update RowDataPacket.js --- lib/protocol/packets/RowDataPacket.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index cd091c765..ba035864a 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -1,6 +1,7 @@ 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() { @@ -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) >= Number.MAX_SAFE_INTEGER || Number(numberString) <= Number.MIN_SAFE_INTEGER))) ? numberString : Number(numberString)); case Types.BIT: From 8d68cdb99b1ed9ef369dd353c788371ce041373a Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 30 Mar 2016 02:46:43 +0900 Subject: [PATCH 03/12] A bug fix for the Types.LONGLONG number range According to MDN(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#Integer_range_for_Number), Integer range for Number is -9007199254740992 to 9007199254740992. But In the original code, 1. There is no range for the negative value. 2. Can't print out 9007199254740993 value. Because of the gt sign at line 103 : Number(numberString) > IEEE_754_BINARY_64_PRECISION. --- lib/protocol/packets/RowDataPacket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index ba035864a..405ac5213 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -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) >= 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: From 2b160b907413bcb0b33f78fddc89f8004a29cf98 Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 30 Mar 2016 03:44:27 +0900 Subject: [PATCH 04/12] A bug fix for the Types.LONGLONG number range According to MDN(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#Integer_range_for_Number), Integer range for Number is -9007199254740992 to 9007199254740992. But In the original code, 1. There is no range for the negative value. 2. Can't print out 9007199254740993 value. Because of the gt sign at line 103 : Number(numberString) > IEEE_754_BINARY_64_PRECISION. Fixed, And re-aligned. --- lib/protocol/packets/RowDataPacket.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index 405ac5213..bc11c981d 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -1,7 +1,6 @@ -var Types = require('../constants/types'); -var Charsets = require('../constants/charsets'); -var Field = require('./Field'); -var IEEE_754_BINARY_64_PRECISION = Math.pow(2, 53); +var Types = require('../constants/types'); +var Charsets = require('../constants/charsets'); +var Field = require('./Field'); module.exports = RowDataPacket; function RowDataPacket() { @@ -100,7 +99,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 || Number(numberString) <= -IEEE_754_BINARY_64_PRECISION))) + : ((supportBigNumbers && (bigNumberStrings || (Number(numberString) > Number.MAX_SAFE_INTEGER || Number(numberString) < Number.MIN_SAFE_INTEGER))) ? numberString : Number(numberString)); case Types.BIT: From 21d8bad5dbc2b7e12f15df829f9d46e19e396d5f Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 30 Mar 2016 07:25:54 +0900 Subject: [PATCH 05/12] add tests --- lib/protocol/packets/RowDataPacket.js | 10 ++--- test/common.js | 3 +- .../connection/test-protocol-bigint.js | 37 +++++++++++++++++++ test0.js | 32 ++++++++++++++++ 4 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 test/integration/connection/test-protocol-bigint.js create mode 100644 test0.js diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index 0912ce047..cb8d754a8 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -1,7 +1,6 @@ -var Types = require('../constants/types'); -var Charsets = require('../constants/charsets'); -var Field = require('./Field'); -var IEEE_754_BINARY_64_PRECISION = Math.pow(2, 53); +var Types = require('../constants/types'); +var Charsets = require('../constants/charsets'); +var Field = require('./Field'); module.exports = RowDataPacket; function RowDataPacket() { @@ -100,8 +99,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))) - ? numberString + : ((supportBigNumbers && (bigNumberStrings || (Number(numberString) > Number.MAX_SAFE_INTEGER || Number(numberString) < Number.MIN_SAFE_INTEGER))) ? numberString : Number(numberString)); case Types.BIT: return parser.parseLengthCodedBuffer(); diff --git a/test/common.js b/test/common.js index 78b3838c5..2d74352e2 100644 --- a/test/common.js +++ b/test/common.js @@ -149,7 +149,8 @@ function mergeTestConfig(config) { host : process.env.MYSQL_HOST, port : process.env.MYSQL_PORT, user : process.env.MYSQL_USER, - password : process.env.MYSQL_PASSWORD + password : process.env.MYSQL_PASSWORD, + supportBigNumbers: true, }, config); return config; diff --git a/test/integration/connection/test-protocol-bigint.js b/test/integration/connection/test-protocol-bigint.js new file mode 100644 index 000000000..cbfaab3ef --- /dev/null +++ b/test/integration/connection/test-protocol-bigint.js @@ -0,0 +1,37 @@ +var assert = require('assert'); +var common = require('../../common'); + +var table = 'bigint_test'; + +common.getTestConnection(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.deepStrictEqual(rows[0].big, '9223372036854775807'); + assert.deepStrictEqual(rows[1].big, '-9223372036854775807'); + assert.deepStrictEqual(rows[2].big, '1111111111111111111'); + assert.deepStrictEqual(rows[3].big, '-1111111111111111111'); + assert.deepStrictEqual(rows[4].big, '9007199254740993'); + assert.deepStrictEqual(rows[5].big, '-9007199254740993'); + connection.end(assert.ifError); + }); +}); diff --git a/test0.js b/test0.js new file mode 100644 index 000000000..88a48172a --- /dev/null +++ b/test0.js @@ -0,0 +1,32 @@ +var mysql = require('mysql'); +var express = require('express') +, http = require('http') +, app = express() +, server = http.createServer(app); + +var db_config = { +connectionLimit : 10, +host : 'localhost', +user : 'root', +password : 'root!', +database : 'kdtestdb', +supportBigNumbers: true, +} + +var pool = mysql.createPool(db_config); + +app.get('/*', function (req, res) { +pool.query('SELECT * FROM test;', function(err, rows, fields) { +if (err){ + console.log("error"); +throw err +} else { + console.log(rows); +res.send(rows); +}; +}); +}); + +var listener = app.listen(8080, function() { + console.log('Express server listening on port ' + listener.address().port); +}); From b55d927a03493d61e119256634ee9df1d215197e Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 30 Mar 2016 07:34:59 +0900 Subject: [PATCH 06/12] Delete test0.js --- test0.js | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 test0.js diff --git a/test0.js b/test0.js deleted file mode 100644 index 88a48172a..000000000 --- a/test0.js +++ /dev/null @@ -1,32 +0,0 @@ -var mysql = require('mysql'); -var express = require('express') -, http = require('http') -, app = express() -, server = http.createServer(app); - -var db_config = { -connectionLimit : 10, -host : 'localhost', -user : 'root', -password : 'root!', -database : 'kdtestdb', -supportBigNumbers: true, -} - -var pool = mysql.createPool(db_config); - -app.get('/*', function (req, res) { -pool.query('SELECT * FROM test;', function(err, rows, fields) { -if (err){ - console.log("error"); -throw err -} else { - console.log(rows); -res.send(rows); -}; -}); -}); - -var listener = app.listen(8080, function() { - console.log('Express server listening on port ' + listener.address().port); -}); From b8ece310ea5620420e57ee671f2dc89b21476afa Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 30 Mar 2016 08:08:52 +0900 Subject: [PATCH 07/12] Fix bigint out of range problem --- lib/protocol/packets/RowDataPacket.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index 56d6286e3..bc11c981d 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -99,12 +99,8 @@ function typeCast(field, parser, timeZone, supportBigNumbers, bigNumberStrings, numberString = parser.parseLengthCodedString(); return (numberString === null || (field.zeroFill && numberString[0] == "0")) ? numberString -<<<<<<< HEAD - : ((supportBigNumbers && (bigNumberStrings || (Number(numberString) > Number.MAX_SAFE_INTEGER || Number(numberString) < Number.MIN_SAFE_INTEGER))) ? numberString -======= : ((supportBigNumbers && (bigNumberStrings || (Number(numberString) > Number.MAX_SAFE_INTEGER || Number(numberString) < Number.MIN_SAFE_INTEGER))) ? numberString ->>>>>>> 2b160b907413bcb0b33f78fddc89f8004a29cf98 : Number(numberString)); case Types.BIT: return parser.parseLengthCodedBuffer(); From 7588c2859285619d05090dd63503515975837907 Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 30 Mar 2016 09:11:53 +0900 Subject: [PATCH 08/12] Fix bigint out of range problem --- test/integration/connection/test-protocol-bigint.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/integration/connection/test-protocol-bigint.js b/test/integration/connection/test-protocol-bigint.js index cbfaab3ef..9feb9fbca 100644 --- a/test/integration/connection/test-protocol-bigint.js +++ b/test/integration/connection/test-protocol-bigint.js @@ -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.deepStrictEqual(rows[0].big, '9223372036854775807'); - assert.deepStrictEqual(rows[1].big, '-9223372036854775807'); - assert.deepStrictEqual(rows[2].big, '1111111111111111111'); - assert.deepStrictEqual(rows[3].big, '-1111111111111111111'); - assert.deepStrictEqual(rows[4].big, '9007199254740993'); - assert.deepStrictEqual(rows[5].big, '-9007199254740993'); + 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'); connection.end(assert.ifError); }); }); From fc77df8e1449d8fc477403a4f013b0268b63b576 Mon Sep 17 00:00:00 2001 From: Dinwy Date: Thu, 31 Mar 2016 07:36:11 +0900 Subject: [PATCH 09/12] Fixed bigint out of range problem --- %HOMEDRIVE%%HOMEPATH%/.nvmw | 1 + lib/protocol/packets/RowDataPacket.js | 9 +++++---- test/common.js | 2 +- ...{test-protocol-bigint.js => test-query-bigint.js} | 12 ++++++------ 4 files changed, 13 insertions(+), 11 deletions(-) create mode 160000 %HOMEDRIVE%%HOMEPATH%/.nvmw rename test/integration/connection/{test-protocol-bigint.js => test-query-bigint.js} (72%) diff --git a/%HOMEDRIVE%%HOMEPATH%/.nvmw b/%HOMEDRIVE%%HOMEPATH%/.nvmw new file mode 160000 index 000000000..80a504b8e --- /dev/null +++ b/%HOMEDRIVE%%HOMEPATH%/.nvmw @@ -0,0 +1 @@ +Subproject commit 80a504b8e51d347c6ee909d3806610c3a6896f64 diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index bc11c981d..008c2b1de 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -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() { @@ -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: diff --git a/test/common.js b/test/common.js index 2d74352e2..ed38d7d66 100644 --- a/test/common.js +++ b/test/common.js @@ -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; diff --git a/test/integration/connection/test-protocol-bigint.js b/test/integration/connection/test-query-bigint.js similarity index 72% rename from test/integration/connection/test-protocol-bigint.js rename to test/integration/connection/test-query-bigint.js index 9feb9fbca..49e48982d 100644 --- a/test/integration/connection/test-protocol-bigint.js +++ b/test/integration/connection/test-query-bigint.js @@ -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); }); }); From 30327964107abf9a9f7139dbd4b0d16a9ea098d6 Mon Sep 17 00:00:00 2001 From: Dinwy Date: Thu, 31 Mar 2016 07:38:16 +0900 Subject: [PATCH 10/12] Fixed bigint out of range problem --- %HOMEDRIVE%%HOMEPATH%/.nvmw | 1 - 1 file changed, 1 deletion(-) delete mode 160000 %HOMEDRIVE%%HOMEPATH%/.nvmw diff --git a/%HOMEDRIVE%%HOMEPATH%/.nvmw b/%HOMEDRIVE%%HOMEPATH%/.nvmw deleted file mode 160000 index 80a504b8e..000000000 --- a/%HOMEDRIVE%%HOMEPATH%/.nvmw +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 80a504b8e51d347c6ee909d3806610c3a6896f64 From 4273828a70ccdd07f8b7264fd69c9b7c31173928 Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 6 Apr 2016 11:16:24 +0900 Subject: [PATCH 11/12] Fix #1371 bigint error --- test/common.js | 5 ++--- test/integration/connection/test-query-bigint.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/common.js b/test/common.js index ed38d7d66..bcead6daa 100644 --- a/test/common.js +++ b/test/common.js @@ -149,9 +149,8 @@ function mergeTestConfig(config) { host : process.env.MYSQL_HOST, port : process.env.MYSQL_PORT, user : process.env.MYSQL_USER, - password : process.env.MYSQL_PASSWORD, - supportBigNumbers: true - }, config); + password : process.env.MYSQL_PASSWORD + }, config); return config; } diff --git a/test/integration/connection/test-query-bigint.js b/test/integration/connection/test-query-bigint.js index 49e48982d..831a03143 100644 --- a/test/integration/connection/test-query-bigint.js +++ b/test/integration/connection/test-query-bigint.js @@ -3,7 +3,7 @@ var common = require('../../common'); var table = 'bigint_test'; -common.getTestConnection(function (err, connection) { +common.getTestConnection({supportBigNumbers: true}, function (err, connection) { assert.ifError(err); common.useTestDb(connection); From fb1d14d1f8be0a1c5cb60b30d0b43d690d578f4d Mon Sep 17 00:00:00 2001 From: Dinwy Date: Wed, 6 Apr 2016 12:55:00 +0900 Subject: [PATCH 12/12] Fix #1371 bigint error --- test/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common.js b/test/common.js index bcead6daa..78b3838c5 100644 --- a/test/common.js +++ b/test/common.js @@ -150,7 +150,7 @@ function mergeTestConfig(config) { port : process.env.MYSQL_PORT, user : process.env.MYSQL_USER, password : process.env.MYSQL_PASSWORD - }, config); + }, config); return config; }