Skip to content
Permalink
Browse files
Merge branch 'feature/CONJS-165' into maintenance/3.x
# Conflicts:
#	README.md
#	lib/cmd/batch-rewrite.js
#	lib/connection.js
#	test/integration/test-auth-plugin.js
#	test/unit/misc/test-parse.js
  • Loading branch information
rusher committed Jun 4, 2021
2 parents 2d0486e + 6b19ca8 commit ca895c6
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 39 deletions.
@@ -35,6 +35,7 @@ class BatchBulk extends Parser {
if (this.opts.timeout) {
const err = Errors.createError(
'Cannot use timeout for Batch statement',
this.sql,
false,
info,
'HY000',
@@ -355,10 +356,10 @@ class BatchBulk extends Parser {
displaySql() {
if (this.opts && this.initialValues) {
if (this.sql.length > this.opts.debugLen) {
return 'sql: ' + this.sql.substring(0, this.opts.debugLen) + '...';
return this.sql.substring(0, this.opts.debugLen) + '...';
}

let sqlMsg = 'sql: ' + this.sql + ' - parameters:';
let sqlMsg = this.sql + ' - parameters:';
sqlMsg += '[';
for (let i = 0; i < this.initialValues.length; i++) {
if (i !== 0) sqlMsg += ',';
@@ -372,7 +373,7 @@ class BatchBulk extends Parser {
sqlMsg += ']';
return sqlMsg;
}
return 'sql: ' + this.sql + ' - parameters:[]';
return this.sql + ' - parameters:[]';
}

success(val) {
@@ -422,6 +423,7 @@ class BatchBulk extends Parser {
if (this.stack) {
err = Errors.createError(
err.message,
this.sql,
err.fatal,
info,
err.sqlState,
@@ -20,7 +20,9 @@ class Command extends EventEmitter {
this.sending = false;
}

displaySql() {}
displaySql() {
return null;
}

/**
* Throw an an unexpected error.
@@ -36,7 +38,7 @@ class Command extends EventEmitter {
if (this.reject) {
process.nextTick(
this.reject,
Errors.createError(msg, fatal, info, sqlState, errno, this.stack, false)
Errors.createError(msg, this.displaySql(), fatal, info, sqlState, errno, this.stack, false)
);
this.resolve = null;
this.reject = null;
@@ -58,7 +60,7 @@ class Command extends EventEmitter {
if (this.reject) {
process.nextTick(
this.reject,
Errors.createError(msg, fatal, info, sqlState, errno, this.stack, false)
Errors.createError(msg, this.displaySql(), fatal, info, sqlState, errno, this.stack, false)
);
this.resolve = null;
this.reject = null;
@@ -79,6 +81,7 @@ class Command extends EventEmitter {
if (this.stack) {
err = Errors.createError(
err.message,
err.sql,
err.fatal,
info,
err.sqlState,
@@ -89,6 +89,7 @@ class CachingSha2PasswordAuth extends PluginAuth {
Errors.createError(
'RSA public key is not available client side. Either set option `cachingRsaPublicKey` to indicate' +
' public key path, or allow public key retrieval with option `allowPublicKeyRetrieval`',
null,
true,
info,
'08S01',
@@ -54,7 +54,7 @@ class Sha256PasswordAuth extends PluginAuth {
Errors.createError(
'RSA public key is not available client side. Either set option `rsaPublicKey` to indicate' +
' public key path, or allow public key retrieval with option `allowPublicKeyRetrieval`',

null,
true,
info,
'08S01',
@@ -194,6 +194,7 @@ class Handshake extends Command {
"Client does not support authentication protocol '" +
pluginName +
"' requested by server. ",
null,
true,
info,
'08004',
@@ -239,6 +240,7 @@ class Handshake extends Command {
if (!Handshake.ensureNodeVersion(11, 6, 0)) {
throw Errors.createError(
'sha256_password authentication plugin require node 11.6+',
null,
true,
info,
'08004',
@@ -252,6 +254,7 @@ class Handshake extends Command {
if (!Handshake.ensureNodeVersion(11, 6, 0)) {
throw Errors.createError(
'caching_sha2_password authentication plugin require node 11.6+',
null,
true,
info,
'08004',
@@ -500,13 +500,13 @@ class Parser extends Command {
displaySql() {
if (this.opts && this.initialValues) {
if (this.sql.length > this.opts.debugLen) {
return 'sql: ' + this.sql.substring(0, this.opts.debugLen) + '...';
return this.sql.substring(0, this.opts.debugLen) + '...';
}

let sqlMsg = 'sql: ' + this.sql + ' - parameters:';
let sqlMsg = this.sql + ' - parameters:';
return this.logParameters(sqlMsg, this.initialValues);
}
return 'sql: ' + this.sql + ' - parameters:[]';
return this.sql + ' - parameters:[]';
}

logParameters(sqlMsg, values) {
@@ -615,6 +615,7 @@ class Parser extends Command {
"' doesn't correspond to query " +
this.sql +
'. Query cancelled. Check for malicious server / proxy',
this.sql,
false,
info,
'45034',
@@ -634,6 +635,7 @@ class Parser extends Command {
out.writeEmptyPacket();
const error = Errors.createError(
'LOCAL INFILE command failed: ' + err.message,
this.sql,
false,
info,
'22000',
@@ -129,6 +129,7 @@ class Query extends Parser {
const err = Errors.createError(
'Cannot use timeout for MariaDB server before 10.1.2. timeout value: ' +
this.opts.timeout,
this.sql,
false,
info,
'HY000',
@@ -143,6 +144,7 @@ class Query extends Parser {
// max_execution time exist, but only for select, and as hint
const err = Errors.createError(
'Cannot use timeout for MySQL server. timeout value: ' + this.opts.timeout,
this.sql,
false,
info,
'HY000',
@@ -167,7 +169,7 @@ class Query extends Parser {
if (this.queryParts.length - 1 > this.values.length) {
this.emit('send_end');
this.throwNewError(
'Parameter at position ' + (this.values.length + 1) + ' is not set\n' + this.displaySql(),
'Parameter at position ' + (this.values.length + 1) + ' is not set',
false,
info,
'HY000',
@@ -159,6 +159,7 @@ class ConnectionOptions {
if (!moment.tz.zone(tzName)) {
throw Errors.createError(
"Unknown IANA timezone '" + tzName + "'.",
null,
true,
null,
'08S01',
@@ -81,6 +81,7 @@ function ConnectionCallback(options) {
if (!callback) {
throw new Errors.createError(
'missing callback parameter',
null,
false,
this.info,
'HY000',
@@ -97,6 +98,7 @@ function ConnectionCallback(options) {
callback(
Errors.createError(
'Connection closed',
null,
true,
this.info,
'08S01',
@@ -66,6 +66,7 @@ function Connection(options) {
return Promise.reject(
Errors.createError(
'Connection closed',
null,
true,
info,
'08S01',
@@ -78,6 +79,7 @@ function Connection(options) {
return Promise.reject(
Errors.createError(
'Connection is already connecting',
null,
true,
info,
'08S01',
@@ -102,6 +104,7 @@ function Connection(options) {
return Promise.reject(
Errors.createError(
'method changeUser not available for MySQL server due to Bug #83472',
null,
false,
info,
'0A000',
@@ -262,7 +265,8 @@ function Connection(options) {
if (!_values) {
return Promise.reject(
Errors.createError(
'Batch must have values set\nsql: ' + _sql + ' - parameters:[]',
'Batch must have values set',
_sql,
false,
info,
'HY000',
@@ -383,6 +387,7 @@ function Connection(options) {
reject(
Errors.createError(
'Ping cannot have negative timeout value',
null,
false,
info,
'0A000',
@@ -392,7 +397,9 @@ function Connection(options) {
return;
}
const tOut = setTimeout(() => {
reject(Errors.createError('Ping timeout', true, info, '0A000', Errors.ER_PING_TIMEOUT));
reject(
Errors.createError('Ping timeout', null, true, info, '0A000', Errors.ER_PING_TIMEOUT)
);
// close connection
_addCommand = _addCommandDisabled;
clearTimeout(_timeout);
@@ -523,6 +530,7 @@ function Connection(options) {
const killResHandler = () => {
const destroyError = Errors.createError(
'Connection destroyed, command was killed',
null,
true,
info,
'08S01',
@@ -579,6 +587,7 @@ function Connection(options) {
this.format = (sql, values) => {
throw Errors.createError(
'"Connection.format intentionally not implemented. please use Connection.query(sql, values), it will be more secure and faster',
null,
false,
info,
'0A000',
@@ -836,6 +845,7 @@ function Connection(options) {
JSON.stringify(opts.sessionVariables) +
'). Error: ' +
initialErr.message,
sessionQuery,
true,
info,
'08S01',
@@ -878,6 +888,7 @@ function Connection(options) {
"Automatic timezone setting fails. Server timezone '" +
serverTimezone +
"' does't have a corresponding IANA timezone. Option timezone must be set according to server timezone",
null,
true,
info,
'08S01',
@@ -935,6 +946,7 @@ function Connection(options) {
return Promise.reject(
Errors.createError(
'Error executing initial sql command: ' + initialErr.message,
null,
true,
info,
'08S01',
@@ -950,25 +962,26 @@ function Connection(options) {
const _executeSessionTimeout = () => {
if (opts.queryTimeout) {
if (info.isMariaDB() && info.hasMinVersion(10, 1, 2)) {
this._queryPromise('SET max_statement_time=' + opts.queryTimeout / 1000).catch(
(initialErr) => {
return Promise.reject(
Errors.createError(
'Error setting session queryTimeout: ' + initialErr.message,
true,
info,
'08S01',
Errors.ER_INITIAL_TIMEOUT_ERROR,
null
)
);
}
);
const query = 'SET max_statement_time=' + opts.queryTimeout / 1000;
this._queryPromise(query).catch((initialErr) => {
return Promise.reject(
Errors.createError(
'Error setting session queryTimeout: ' + initialErr.message,
query,
true,
info,
'08S01',
Errors.ER_INITIAL_TIMEOUT_ERROR,
null
)
);
});
} else {
return Promise.reject(
Errors.createError(
'Can only use queryTimeout for MariaDB server after 10.1.1. queryTimeout value: ' +
opts.queryTimeout,
null,
opts.queryTimeout,
false,
info,
'HY000',
@@ -1159,6 +1172,7 @@ function Connection(options) {
packet.end +
')\n' +
Utils.log(opts, packet.buf, packet.pos, packet.end),
null,
true,
info,
'08S01',
@@ -1181,7 +1195,8 @@ function Connection(options) {
if (_status === Status.CLOSING || _status === Status.CLOSED) {
return Promise.reject(
Errors.createError(
'Cannot execute new commands: connection closed\nsql: ' + sql,
'Cannot execute new commands: connection closed',
sql,
true,
info,
'08S01',
@@ -1215,6 +1230,7 @@ function Connection(options) {
'Connection timeout: failed to create socket after ' +
(Date.now() - initialConnectionTime) +
'ms',
null,
true,
info,
'08S01',
@@ -1230,7 +1246,14 @@ function Connection(options) {
* @private
*/
const _socketTimeoutReached = function () {
const err = Errors.createError('socket timeout', true, info, '08S01', Errors.ER_SOCKET_TIMEOUT);
const err = Errors.createError(
'socket timeout',
null,
true,
info,
'08S01',
Errors.ER_SOCKET_TIMEOUT
);
const packetMsgs = info.getLastPackets();
if (packetMsgs !== '') {
err.message = err.message + '\nlast received packets:\n' + packetMsgs;
@@ -1314,7 +1337,7 @@ function Connection(options) {
*/
const _addCommandDisabled = (cmd) => {
cmd.throwNewError(
'Cannot execute new commands: connection closed\n' + cmd.displaySql(),
'Cannot execute new commands: connection closed',
true,
info,
'08S01',
@@ -1340,6 +1363,7 @@ function Connection(options) {
if (!err) {
err = Errors.createError(
'socket has unexpectedly been closed',
null,
true,
info,
'08S01',

0 comments on commit ca895c6

Please sign in to comment.