Skip to content

Add bigNumberStrings option for forcing BIGINTs as strings (always) #437

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 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/ConnectionConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '';
Expand Down
17 changes: 11 additions & 6 deletions lib/protocol/packets/RowDataPacket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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() );
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down