Comparing version 2.5.1 to 2.5.2
# Change Log | ||
## [2.5.2](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.5.2) (04 Dec 2020) | ||
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.5.1...2.5.2) | ||
* [CONJS-151] bulk batch error (parameter truncation) #137 | ||
* [CONJS-152] correction when enabling the `permitLocalInfile` option and some initial commands | ||
* [CONJS-154] Timezone support correction and clarification | ||
* [CONJS-155] correction to support for node.js 10.13 to 10.19 | ||
* [CONJS-156] Ensure setting capability PLUGIN_AUTH only if server has it | ||
documentation improvement | ||
## [2.5.1](https://github.com/mariadb-corporation/mariadb-connector-nodejs/tree/2.5.1) (23 Oct 2020) | ||
@@ -4,0 +16,0 @@ [Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-nodejs/compare/2.5.0...2.5.1) |
@@ -63,3 +63,3 @@ 'use strict'; | ||
if (this.opts.connectAttributes && info.serverCapabilities & Capabilities.CONNECT_ATTRS) { | ||
if (info.clientCapabilities & Capabilities.CONNECT_ATTRS) { | ||
out.writeInt8(0xfc); | ||
@@ -66,0 +66,0 @@ let initPos = out.pos; //save position, assuming connection attributes length will be less than 2 bytes length |
@@ -7,2 +7,3 @@ 'use strict'; | ||
const Long = require('long'); | ||
const moment = require('moment-timezone'); | ||
const QUOTE = 0x27; | ||
@@ -16,3 +17,7 @@ | ||
this.initialValues = values; | ||
this.getDateQuote = this.opts.tz ? CommonText.getTimezoneDate : CommonText.getLocalDate; | ||
this.getDateQuote = this.opts.tz | ||
? this.opts.tz === 'Etc/UTC' | ||
? CommonText.getUtcDate | ||
: CommonText.getTimezoneDate | ||
: CommonText.getLocalDate; | ||
} | ||
@@ -403,7 +408,18 @@ | ||
function getUtcDate(date, opts) { | ||
const year = date.getUTCFullYear(); | ||
const mon = date.getUTCMonth() + 1; | ||
const day = date.getUTCDate(); | ||
const hour = date.getUTCHours(); | ||
const min = date.getUTCMinutes(); | ||
const sec = date.getUTCSeconds(); | ||
const ms = date.getUTCMilliseconds(); | ||
return getDatePartQuote(year, mon, day, hour, min, sec, ms); | ||
} | ||
function getTimezoneDate(date, opts) { | ||
if (date.getMilliseconds() != 0) { | ||
return opts.tz(date).format("'YYYY-MM-DD HH:mm:ss.SSS'"); | ||
return moment.tz(date, opts.tz).format("'YYYY-MM-DD HH:mm:ss.SSS'"); | ||
} | ||
return opts.tz(date).format("'YYYY-MM-DD HH:mm:ss'"); | ||
return moment.tz(date, opts.tz).format("'YYYY-MM-DD HH:mm:ss'"); | ||
} | ||
@@ -413,2 +429,3 @@ | ||
module.exports.getTimezoneDate = getTimezoneDate; | ||
module.exports.getUtcDate = getUtcDate; | ||
module.exports.getLocalDate = getLocalDate; |
@@ -20,3 +20,2 @@ 'use strict'; | ||
Capabilities.SESSION_TRACK | | ||
Capabilities.PLUGIN_AUTH | | ||
Capabilities.PLUGIN_AUTH_LENENC_CLIENT_DATA; | ||
@@ -28,3 +27,7 @@ | ||
if (opts.connectAttributes) { | ||
if (info.serverCapabilities & Capabilities.PLUGIN_AUTH) { | ||
capabilities |= Capabilities.PLUGIN_AUTH; | ||
} | ||
if (opts.connectAttributes && info.serverCapabilities & Capabilities.CONNECT_ATTRS) { | ||
capabilities |= Capabilities.CONNECT_ATTRS; | ||
@@ -50,3 +53,3 @@ } | ||
if (opts.database) { | ||
if (opts.database && info.serverCapabilities & Capabilities.CONNECT_WITH_DB) { | ||
capabilities |= Capabilities.CONNECT_WITH_DB; | ||
@@ -53,0 +56,0 @@ } |
@@ -77,3 +77,3 @@ 'use strict'; | ||
if (opts.connectAttributes && info.serverCapabilities & Capabilities.CONNECT_ATTRS) { | ||
if (info.clientCapabilities & Capabilities.CONNECT_ATTRS) { | ||
out.writeInt8(0xfc); | ||
@@ -80,0 +80,0 @@ let initPos = out.pos; //save position, assuming connection attributes length will be less than 2 bytes length |
@@ -108,2 +108,3 @@ 'use strict'; | ||
this.timezone = opts.timezone || 'local'; | ||
this.skipSetTimezone = opts.skipSetTimezone || false; | ||
if (this.timezone && this.timezone !== 'local' && this.timezone !== 'auto') { | ||
@@ -125,9 +126,7 @@ let tzName = this.timezone; | ||
} | ||
tzName = 'Etc/GMT' + (matched[1] === '-' ? '+' : '') + hour; | ||
console.log( | ||
"warning: please use IANA standard timezone format ('Etc/GMT" + | ||
(matched[1] === '-' ? '+' : '') + | ||
hour + | ||
"')" | ||
); | ||
if (hour == 0) { | ||
tzName = 'Etc/UTC'; | ||
} else { | ||
tzName = 'Etc/GMT' + (matched[1] === '-' ? '+' : '') + hour; | ||
} | ||
} | ||
@@ -139,4 +138,4 @@ } | ||
} else { | ||
this.tz = moment.tz.setDefault(tzName); | ||
if (!this.tz.defaultZone) { | ||
this.tz = tzName; | ||
if (!moment.tz.zone(tzName)) { | ||
throw Errors.createError( | ||
@@ -193,2 +192,3 @@ "Unknown IANA timezone '" + tzName + "'.", | ||
if (opts.arrayParenthesis) opts.arrayParenthesis = opts.arrayParenthesis == 'true'; | ||
if (opts.skipSetTimezone) opts.skipSetTimezone = opts.skipSetTimezone == 'true'; | ||
@@ -195,0 +195,0 @@ if (opts.checkDuplicate) opts.checkDuplicate = opts.checkDuplicate == 'true'; |
@@ -159,3 +159,3 @@ 'use strict'; | ||
*/ | ||
this.query = (sql, values) => { | ||
this._queryPromise = (sql, values) => { | ||
let _cmdOpt, | ||
@@ -788,30 +788,52 @@ _sql, | ||
const _checkServerTimezone = () => { | ||
if (opts.timezone !== 'auto') { | ||
return Promise.resolve(); | ||
} | ||
return this.query('SELECT @@system_time_zone stz, @@time_zone tz').then((res) => { | ||
const serverTimezone = res[0].tz === 'SYSTEM' ? res[0].stz : res[0].tz; | ||
const serverZone = moment.tz.zone(serverTimezone); | ||
if (serverZone) { | ||
if (serverTimezone === moment.tz.guess()) { | ||
//db server and client use same timezone, avoid any conversion | ||
opts.tz = null; | ||
if (opts.timezone === 'auto') { | ||
return this._queryPromise('SELECT @@system_time_zone stz, @@time_zone tz').then((res) => { | ||
const serverTimezone = res[0].tz === 'SYSTEM' ? res[0].stz : res[0].tz; | ||
const serverZone = moment.tz.zone(serverTimezone); | ||
if (serverZone) { | ||
const localTz = moment.tz.guess(); | ||
if (serverTimezone === localTz) { | ||
//db server and client use same timezone, avoid any conversion | ||
opts.tz = null; | ||
} else { | ||
opts.localTz = localTz; | ||
opts.tz = serverTimezone; | ||
} | ||
} else { | ||
opts.tz = moment.tz.setDefault(serverTimezone); | ||
return Promise.reject( | ||
Errors.createError( | ||
"Automatic timezone setting fails. Server timezone '" + | ||
serverTimezone + | ||
"' does't have a corresponding IANA timezone. Option timezone must be set according to server timezone", | ||
true, | ||
info, | ||
'08S01', | ||
Errors.ER_WRONG_AUTO_TIMEZONE | ||
) | ||
); | ||
} | ||
} else { | ||
return Promise.reject( | ||
Errors.createError( | ||
"Automatic timezone setting fails. Server timezone '" + | ||
serverTimezone + | ||
"' does't have a corresponding IANA timezone. Option timezone must be set according to server timezone", | ||
true, | ||
info, | ||
'08S01', | ||
Errors.ER_WRONG_AUTO_TIMEZONE | ||
) | ||
); | ||
return Promise.resolve(); | ||
}); | ||
} | ||
if (opts.tz && !opts.skipSetTimezone) { | ||
let tz = opts.tz; | ||
if (opts.tz === 'Etc/UTC') { | ||
tz = '+00:00'; | ||
} else if (opts.tz.startsWith('Etc/GMT')) { | ||
let zone = moment.tz.zone(opts.tz); | ||
tz = zone.abbrs[0] + ':00'; | ||
} | ||
return Promise.resolve(); | ||
}); | ||
return this._queryPromise('SET time_zone=?', tz) | ||
.then((res) => { | ||
return Promise.resolve(); | ||
}) | ||
.catch((err) => { | ||
console.log( | ||
`warning: setting timezone '${opts.tz}' fails on server.\n look at https://mariadb.com/kb/en/mysql_tzinfo_to_sql/ to load IANA timezone.\nSetting timezone can be disabled with option \`skipSetTimezone\`` | ||
); | ||
return Promise.resolve(); | ||
}); | ||
} | ||
return Promise.resolve(); | ||
}; | ||
@@ -823,3 +845,3 @@ | ||
} | ||
return this.query('SELECT @@VERSION AS v').then((res) => { | ||
return this._queryPromise('SELECT @@VERSION AS v').then((res) => { | ||
info.serverVersion.raw = res[0].v; | ||
@@ -837,23 +859,17 @@ info.serverVersion.mariaDb = info.serverVersion.raw.includes('MariaDB'); | ||
initialArr.forEach((sql) => { | ||
initialPromises.push( | ||
new Promise(function (resolve, reject) { | ||
const errorHandling = (initialErr) => { | ||
reject( | ||
Errors.createError( | ||
'Error executing initial sql command: ' + initialErr.message, | ||
true, | ||
info, | ||
'08S01', | ||
Errors.ER_INITIAL_SQL_ERROR, | ||
null | ||
) | ||
); | ||
}; | ||
const cmd = new Query(resolve, errorHandling, null, opts, sql, null); | ||
if (opts.trace) Error.captureStackTrace(cmd); | ||
_addCommand(cmd); | ||
}) | ||
initialPromises.push(this._queryPromise(sql)); | ||
}); | ||
return Promise.all(initialPromises).catch((initialErr) => { | ||
return Promise.reject( | ||
Errors.createError( | ||
'Error executing initial sql command: ' + initialErr.message, | ||
true, | ||
info, | ||
'08S01', | ||
Errors.ER_INITIAL_SQL_ERROR, | ||
null | ||
) | ||
); | ||
}); | ||
return Promise.all(initialPromises); | ||
} | ||
@@ -866,5 +882,5 @@ return Promise.resolve(); | ||
if (info.isMariaDB() && info.hasMinVersion(10, 1, 2)) { | ||
return new Promise(function (resolve, reject) { | ||
const errorHandling = (initialErr) => { | ||
reject( | ||
this._queryPromise('SET max_statement_time=' + opts.queryTimeout / 1000).catch( | ||
(initialErr) => { | ||
return Promise.reject( | ||
Errors.createError( | ||
@@ -879,14 +895,4 @@ 'Error setting session queryTimeout: ' + initialErr.message, | ||
); | ||
}; | ||
const cmd = new Query( | ||
resolve, | ||
errorHandling, | ||
null, | ||
opts, | ||
'SET max_statement_time=' + opts.queryTimeout / 1000, | ||
null | ||
); | ||
if (opts.trace) Error.captureStackTrace(cmd); | ||
_addCommand(cmd); | ||
}); | ||
} | ||
); | ||
} else { | ||
@@ -992,3 +998,3 @@ return Promise.reject( | ||
}; | ||
_status = Status.INIT_CMD; | ||
_executeSessionVariableQuery() | ||
@@ -1192,3 +1198,3 @@ .then(() => { | ||
//send immediately only if no current active receiver | ||
if (_sendQueue.isEmpty() && _status === Status.CONNECTED) { | ||
if (_sendQueue.isEmpty() && (_status === Status.INIT_CMD || _status === Status.CONNECTED)) { | ||
if (_receiveQueue.peekFront()) { | ||
@@ -1418,2 +1424,3 @@ _receiveQueue.push(cmd); | ||
this.query = this._queryPromise; | ||
this.escape = Utils.escape.bind(this, opts, info); | ||
@@ -1420,0 +1427,0 @@ this.escapeId = Utils.escapeId.bind(this, opts, info); |
@@ -7,7 +7,8 @@ 'use strict'; | ||
AUTHENTICATING: 3, | ||
CONNECTED: 4, | ||
CLOSING: 5, | ||
CLOSED: 6 | ||
INIT_CMD: 4, | ||
CONNECTED: 5, | ||
CLOSING: 6, | ||
CLOSED: 7 | ||
}; | ||
module.exports.Status = Status; |
'use strict'; | ||
const moment = require('moment-timezone'); | ||
const Iconv = require('iconv-lite'); | ||
@@ -30,3 +31,7 @@ const SMALL_BUFFER_SIZE = 1024; | ||
this.haveErrorResponse = false; | ||
this.writeBinaryDate = opts.tz ? this.writeBinaryTimezoneDate : this.writeBinaryLocalDate; | ||
this.writeBinaryDate = opts.tz | ||
? opts.tz === 'Etc/UTC' | ||
? this.writeBinaryUtcDate | ||
: this.writeBinaryTimezoneDate | ||
: this.writeBinaryLocalDate; | ||
if (this.encoding === 'utf8') { | ||
@@ -357,3 +362,3 @@ this.writeLengthEncodedString = this.writeDefaultLengthEncodedString; | ||
if (byteLength + 9 > this.buf.length - this.pos) { | ||
if (this.buf.length < MAX_BUFFER_SIZE) flushed = this.growBuffer(byteLength); | ||
if (this.buf.length < MAX_BUFFER_SIZE) flushed = this.growBuffer(byteLength + 9); | ||
@@ -382,2 +387,13 @@ if (byteLength > this.buf.length - this.pos) { | ||
writeBinaryUtcDate(date, opts) { | ||
const year = date.getUTCFullYear(); | ||
const mon = date.getUTCMonth() + 1; | ||
const day = date.getUTCDate(); | ||
const hour = date.getUTCHours(); | ||
const min = date.getUTCMinutes(); | ||
const sec = date.getUTCSeconds(); | ||
const ms = date.getUTCMilliseconds(); | ||
return this._writeBinaryDate(year, mon, day, hour, min, sec, ms); | ||
} | ||
_writeBinaryDate(year, mon, day, hour, min, sec, ms) { | ||
@@ -429,12 +445,12 @@ let len = ms === 0 ? 7 : 11; | ||
writeBinaryTimezoneDate(date, opts) { | ||
const formated = opts.tz(date).format('YYYY-MM-DD HH:mm:ss.SSSSSS'); | ||
const dateZoned = new Date(formated + 'Z'); | ||
const year = dateZoned.getUTCFullYear(); | ||
const mon = dateZoned.getUTCMonth() + 1; | ||
const day = dateZoned.getUTCDate(); | ||
const hour = dateZoned.getUTCHours(); | ||
const min = dateZoned.getUTCMinutes(); | ||
const sec = dateZoned.getUTCSeconds(); | ||
const ms = dateZoned.getUTCMilliseconds(); | ||
const dateZoned = new Date( | ||
moment.tz(date, opts.localTz).tz(opts.tz).format('YYYY-MM-DD HH:mm:ss.SSSSSS') | ||
); | ||
const year = dateZoned.getFullYear(); | ||
const mon = dateZoned.getMonth() + 1; | ||
const day = dateZoned.getDate(); | ||
const hour = dateZoned.getHours(); | ||
const min = dateZoned.getMinutes(); | ||
const sec = dateZoned.getSeconds(); | ||
const ms = dateZoned.getMilliseconds(); | ||
return this._writeBinaryDate(year, mon, day, hour, min, sec, ms); | ||
@@ -441,0 +457,0 @@ } |
@@ -6,2 +6,3 @@ 'use strict'; | ||
const Long = require('long'); | ||
const moment = require('moment-timezone'); | ||
@@ -187,5 +188,18 @@ /** | ||
readInt64() { | ||
const val = this.buf.readBigInt64LE(this.pos); | ||
// could use readBigInt64LE when support would be 10.20+ | ||
const val = | ||
this.buf[this.pos + 4] + | ||
this.buf[this.pos + 5] * 2 ** 8 + | ||
this.buf[this.pos + 6] * 2 ** 16 + | ||
(this.buf[this.pos + 7] << 24); | ||
const vv = | ||
(BigInt(val) << 32n) + | ||
BigInt( | ||
this.buf[this.pos] + | ||
this.buf[this.pos + 1] * 2 ** 8 + | ||
this.buf[this.pos + 2] * 2 ** 16 + | ||
this.buf[this.pos + 3] * 2 ** 24 | ||
); | ||
this.pos += 8; | ||
return val; | ||
return vv; | ||
} | ||
@@ -366,3 +380,5 @@ | ||
if (opts.tz) { | ||
return new Date(opts.tz(str).clone().tz(opts.localTz).format('YYYY-MM-DD HH:mm:ss.SSSSSS')); | ||
return new Date( | ||
moment.tz(str, opts.tz).clone().tz(opts.localTz).format('YYYY-MM-DD HH:mm:ss.SSSSSS') | ||
); | ||
} | ||
@@ -369,0 +385,0 @@ return new Date(str); |
@@ -131,3 +131,5 @@ 'use strict'; | ||
return opts.tz | ||
? CommonText.getTimezoneDate(value, opts) | ||
? opts.tz === 'Etc/UTC' | ||
? CommonText.getUtcDate(value, opts) | ||
: CommonText.getTimezoneDate(value, opts) | ||
: CommonText.getLocalDate(value, opts); | ||
@@ -134,0 +136,0 @@ } else if (Buffer.isBuffer(value)) { |
{ | ||
"name": "mariadb", | ||
"version": "2.5.1", | ||
"version": "2.5.2", | ||
"description": "fast mariadb/mysql connector.", | ||
@@ -49,27 +49,27 @@ "main": "promise.js", | ||
"@types/geojson": "^7946.0.7", | ||
"@types/node": "^14.11.2", | ||
"@types/node": "^14.14.7", | ||
"denque": "^1.4.1", | ||
"iconv-lite": "^0.6.2", | ||
"long": "^4.0.0", | ||
"moment-timezone": "^0.5.31", | ||
"moment-timezone": "^0.5.32", | ||
"please-upgrade-node": "^3.2.0" | ||
}, | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^4.3.0", | ||
"@typescript-eslint/parser": "^4.3.0", | ||
"@typescript-eslint/eslint-plugin": "^4.7.0", | ||
"@typescript-eslint/parser": "^4.7.0", | ||
"benchmark": "^2.1.4", | ||
"chai": "^4.2.0", | ||
"codecov": "^3.8.0", | ||
"codecov": "^3.8.1", | ||
"colors": "^1.4.0", | ||
"dom-parser": "^0.1.6", | ||
"error-stack-parser": "^2.0.6", | ||
"eslint": "^7.11.0", | ||
"eslint-config-prettier": "^6.12.0", | ||
"eslint": "^7.13.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-plugin-markdown": "^1.0.1", | ||
"eslint-plugin-prettier": "^3.1.0", | ||
"mocha": "^8.1.3", | ||
"mocha": "^8.2.1", | ||
"mocha-lcov-reporter": "^1.3.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^2.1.2", | ||
"typescript": "^4.0.3" | ||
"typescript": "^4.0.5" | ||
}, | ||
@@ -76,0 +76,0 @@ "bugs": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
534502
13927
Updated@types/node@^14.14.7
Updatedmoment-timezone@^0.5.32