Skip to content

Commit 09683e1

Browse files
committed
Fix mysqljs#635: Make inflation of dates optional
1 parent a04b288 commit 09683e1

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ issue [#501](https://github.com/felixge/node-mysql/issues/501). (Default: `'fals
155155
objects only when they cannot be accurately represented with [JavaScript Number objects] (http://ecma262-5.com/ELS5_HTML.htm#Section_8.5)
156156
(which happens when they exceed the [-2^53, +2^53] range), otherwise they will be returned as
157157
Number objects. This option is ignored if `supportBigNumbers` is disabled.
158+
* `dateStrings`: Force date types (TIMESTAMP, DATETIME, DATE) to be returned as strings rather then
159+
inflated into JavaScript Date objects. (Default: `false`)
158160
* `debug`: Prints protocol details to stdout. (Default: `false`)
159161
* `multipleStatements`: Allow multiple mysql statements per query. Be careful
160162
with this, it exposes you to SQL injection attacks. (Default: `false`)

lib/ConnectionConfig.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function ConnectionConfig(options) {
1717
this.insecureAuth = options.insecureAuth || false;
1818
this.supportBigNumbers = options.supportBigNumbers || false;
1919
this.bigNumberStrings = options.bigNumberStrings || false;
20+
this.dateStrings = options.dateStrings || false;
2021
this.debug = options.debug;
2122
this.stringifyObjects = options.stringifyObjects || false;
2223
this.timezone = options.timezone || 'local';

lib/protocol/packets/RowDataPacket.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function RowDataPacket() {
1010
RowDataPacket.prototype.parse = function(parser, fieldPackets, typeCast, nestTables, connection) {
1111
var self = this;
1212
var next = function () {
13-
return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings);
13+
return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings, connection.config.dateStrings);
1414
};
1515

1616
for (var i = 0; i < fieldPackets.length; i++) {
@@ -21,7 +21,7 @@ RowDataPacket.prototype.parse = function(parser, fieldPackets, typeCast, nestTab
2121
value = typeCast.apply(connection, [ new Field({ packet: fieldPacket, parser: parser }), next ]);
2222
} else {
2323
value = (typeCast)
24-
? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings)
24+
? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings, connection.config.dateStrings)
2525
: ( (fieldPacket.charsetNr === Charsets.BINARY)
2626
? parser.parseLengthCodedBuffer()
2727
: parser.parseLengthCodedString() );
@@ -38,7 +38,7 @@ RowDataPacket.prototype.parse = function(parser, fieldPackets, typeCast, nestTab
3838
}
3939
};
4040

41-
RowDataPacket.prototype._typeCast = function(field, parser, timeZone, supportBigNumbers, bigNumberStrings) {
41+
RowDataPacket.prototype._typeCast = function(field, parser, timeZone, supportBigNumbers, bigNumberStrings, dateStrings) {
4242
var numberString;
4343

4444
switch (field.type) {
@@ -47,6 +47,9 @@ RowDataPacket.prototype._typeCast = function(field, parser, timeZone, supportBig
4747
case Types.DATETIME:
4848
case Types.NEWDATE:
4949
var dateString = parser.parseLengthCodedString();
50+
if (dateStrings) {
51+
return dateString;
52+
}
5053
var dt;
5154

5255
if (dateString === null) {

0 commit comments

Comments
 (0)