diff --git a/lib/ConnectionConfig.js b/lib/ConnectionConfig.js index 9cc4446b0..46d648a98 100644 --- a/lib/ConnectionConfig.js +++ b/lib/ConnectionConfig.js @@ -16,6 +16,7 @@ function ConnectionConfig(options) { this.database = options.database; this.insecureAuth = options.insecureAuth || false; this.supportBigNumbers = options.supportBigNumbers || false; + this.bigNumberStrings = options.bigNumberStrings || false; this.debug = options.debug; this.timezone = options.timezone || 'local'; this.flags = options.flags || ''; diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index d270954c9..63937b77c 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -10,7 +10,7 @@ function RowDataPacket() { RowDataPacket.prototype.parse = function(parser, fieldPackets, typeCast, nestTables, connection) { var self = this; var next = function () { - return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers); + return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings); }; for (var i = 0; i < fieldPackets.length; i++) { @@ -21,7 +21,7 @@ RowDataPacket.prototype.parse = function(parser, fieldPackets, typeCast, nestTab value = typeCast.apply(connection, [ new Field({ packet: fieldPacket, parser: parser }), next ]); } else { value = (typeCast) - ? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers) + ? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings) : ( (fieldPacket.charsetNr === Charsets.BINARY) ? parser.parseLengthCodedBuffer() : parser.parseLengthCodedString() ); @@ -38,7 +38,9 @@ RowDataPacket.prototype.parse = function(parser, fieldPackets, typeCast, nestTab } }; -RowDataPacket.prototype._typeCast = function(field, parser, timeZone, supportBigNumbers) { +RowDataPacket.prototype._typeCast = function(field, parser, timeZone, supportBigNumbers, bigNumberStrings) { + var numberString; + switch (field.type) { case Types.TIMESTAMP: case Types.DATE: @@ -72,12 +74,15 @@ RowDataPacket.prototype._typeCast = function(field, parser, timeZone, supportBig case Types.YEAR: case Types.FLOAT: case Types.DOUBLE: - case Types.LONGLONG: case Types.NEWDECIMAL: - var numberString = parser.parseLengthCodedString(); + numberString = parser.parseLengthCodedString(); + return (numberString === null || (field.zeroFill && numberString[0] == "0")) + ? numberString : Number(numberString); + case Types.LONGLONG: + numberString = parser.parseLengthCodedString(); return (numberString === null || (field.zeroFill && numberString[0] == "0")) ? numberString - : ((supportBigNumbers && Number(numberString) > IEEE_754_BINARY_64_PRECISION) + : ((supportBigNumbers && (bigNumberStrings || (Number(numberString) > IEEE_754_BINARY_64_PRECISION))) ? numberString : Number(numberString)); case Types.BIT: