Skip to content

Commit 9cc56fb

Browse files
committed
fix non-standard invalid date test
NO_ZERO_DATE mode and NO_ZERO_IN_DATE mode are part of the strict SQL mode used by MySQL 8.0. Non-standard dates like '0000-00-00' are now stored and retrieved as NULL. This patch introduces changes to one of the integration tests to ensure this change in behavior is accounted for with the latest MySQL server versions.
1 parent f939119 commit 9cc56fb

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

lib/packets/packet.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// This file was modified by Oracle on June 1, 2021.
2+
// A comment describing some changes in the strict default SQL mode regarding
3+
// non-standard dates was introduced.
4+
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
5+
16
'use strict';
27

38
const ErrorCodeToName = require('../constants/errors.js');
@@ -274,6 +279,11 @@ class Packet {
274279
if (length > 10) {
275280
ms = this.readInt32() / 1000;
276281
}
282+
// NO_ZERO_DATE mode and NO_ZERO_IN_DATE mode are part of the strict
283+
// default SQL mode used by MySQL 8.0. This means that non-standard
284+
// dates like '0000-00-00' become NULL. For older versions and other
285+
// possible MySQL flavours we still need to account for the
286+
// non-standard behaviour.
277287
if (y + m + d + H + M + S + ms === 0) {
278288
return INVALID_DATE;
279289
}

test/integration/connection/test-invalid-date-result.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// This file was modified by Oracle on June 1, 2021.
2+
// The test has been updated to be able to pass with different default
3+
// strict modes used by different MySQL server versions.
4+
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
5+
16
'use strict';
27

38
const common = require('../../common');
@@ -6,12 +11,34 @@ const assert = require('assert');
611

712
let rows = undefined;
813

9-
connection.execute('SELECT TIMESTAMP(0000-00-00) t', [], (err, _rows) => {
14+
// Disable NO_ZERO_DATE mode and NO_ZERO_IN_DATE mode to ensure the old
15+
// behaviour.
16+
const strictModes = ['NO_ZERO_DATE', 'NO_ZERO_IN_DATE'];
17+
18+
connection.query('SELECT variable_value as value FROM performance_schema.session_variables where variable_name = ?', ['sql_mode'], (err, _rows) => {
1019
if (err) {
1120
throw err;
1221
}
13-
rows = _rows;
14-
connection.end();
22+
23+
const deprecatedSqlMode = _rows[0].value
24+
.split(',')
25+
.filter(mode => strictModes.indexOf(mode) === -1)
26+
.join(',');
27+
28+
connection.query(`SET sql_mode=?`, [deprecatedSqlMode], err => {
29+
if (err) {
30+
throw err;
31+
}
32+
33+
connection.execute('SELECT TIMESTAMP(0000-00-00) t', [], (err, _rows) => {
34+
if (err) {
35+
throw err;
36+
}
37+
38+
rows = _rows;
39+
connection.end();
40+
});
41+
});
1542
});
1643

1744
function isInvalidTime(t) {

0 commit comments

Comments
 (0)