Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mariadb

Package Overview
Dependencies
Maintainers
3
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mariadb - npm Package Compare versions

Comparing version 3.2.2 to 3.2.3

15

lib/cmd/batch-bulk.js

@@ -216,3 +216,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

if (opts.logger.query)
opts.logger.query(`BULK: (${this.prepare.id}) sql: ${opts.logger.logParam ? this.displaySql() : this.sql}`);
opts.logger.query(`BULK: (${this.prepare.id}) sql: ${opts.logParam ? this.displaySql() : this.sql}`);
const parameterCount = this.prepare.parameterCount;

@@ -254,3 +254,3 @@ this.rowIdx = 0;

lastCmdData = null;
if (!this.rowIdx >= this.values.length) {
if (this.rowIdx >= this.values.length) {
break;

@@ -358,6 +358,5 @@ }

let param = this.initialValues[i];
sqlMsg = this.logParameters(sqlMsg, param);
sqlMsg = Parser.logParameters(this.opts, sqlMsg, param);
if (sqlMsg.length > this.opts.debugLen) {
sqlMsg = sqlMsg.substring(0, this.opts.debugLen) + '...';
break;
return sqlMsg.substring(0, this.opts.debugLen) + '...';
}

@@ -488,5 +487,5 @@ }

this.throwNewError(
`Expect ${nbParameter} parameters, but at index ${r}, parameters only contains ${
this.values[r].length
}\n ${this.displaySql()}`,
`Expect ${nbParameter} parameters, but at index ${r}, parameters only contains ${this.values[r].length}\n ${
this.opts.logParam ? this.displaySql() : this.sql
}`,
false,

@@ -493,0 +492,0 @@ info,

@@ -8,2 +8,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

const ExecuteStream = require('../execute-stream');
const Parser = require('../parser');

@@ -41,2 +42,12 @@ /**

if (this.isClose()) {
let sql = this.query;
if (this.conn.opts.logParam) {
if (this.query.length > this.conn.opts.debugLen) {
sql = this.query.substring(0, this.conn.opts.debugLen) + '...';
} else {
let sqlMsg = this.query + ' - parameters:';
sql = Parser.logParameters(this.conn.opts, sqlMsg, values);
}
}
const error = Errors.createError(

@@ -47,3 +58,3 @@ `Execute fails, prepare command as already been closed`,

'22000',
this.query
sql
);

@@ -50,0 +61,0 @@

@@ -44,3 +44,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

sqlState,
this.displaySql(),
this.opts && this.opts.logParam ? this.displaySql() : this.sql,
fatal,

@@ -84,3 +84,3 @@ this.cmdParam ? this.cmdParam.stack : null,

sendCancelled(msg, errno, info) {
const err = Errors.createError(msg, errno, info, 'HY000', this.displaySql());
const err = Errors.createError(msg, errno, info, 'HY000', this.opts.logParam ? this.displaySql() : this.sql);
this.emit('send_end');

@@ -87,0 +87,0 @@ this.throwError(err, info);

@@ -60,5 +60,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

if (opts.logger.query)
opts.logger.query(
`EXECUTE: (${this.prepare.id}) sql: ${opts.logger.logParam ? this.displaySql() : this.sql}`
);
opts.logger.query(`EXECUTE: (${this.prepare.id}) sql: ${opts.logParam ? this.displaySql() : this.sql}`);
if (!this.longDataStep) {

@@ -77,3 +75,3 @@ this.longDataStep = true;

if (opts.logger.query)
opts.logger.query(`EXECUTE: (${this.prepare.id}) sql: ${opts.logger.logParam ? this.displaySql() : this.sql}`);
opts.logger.query(`EXECUTE: (${this.prepare.id}) sql: ${opts.logParam ? this.displaySql() : this.sql}`);
this.sendComStmtExecute(out, info);

@@ -93,3 +91,5 @@ }

this.sendCancelled(
`Parameter at position ${this.values.length} is not set\\nsql: ${this.displaySql()}`,
`Parameter at position ${this.values.length} is not set\\nsql: ${
this.opts.logParam ? this.displaySql() : this.sql
}`,
Errors.ER_MISSING_PARAMETER,

@@ -96,0 +96,0 @@ info

@@ -72,3 +72,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

info.status = packet.readUInt16();
let mustRedirect = false;
if (info.status & ServerStatus.SESSION_STATE_CHANGED) {

@@ -101,2 +101,7 @@ packet.skip(2); //skip warning count

case 'redirect_url':
mustRedirect = true;
info.redirect(value, this.successEnd);
break;
case 'connection_id':

@@ -121,3 +126,4 @@ info.threadId = parseInt(value);

}
return this.successEnd();
if (!mustRedirect) this.successEnd();
return;

@@ -124,0 +130,0 @@ //*********************************************************************************************************

@@ -58,3 +58,7 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

case 0xff:
const err = packet.readError(info, this.displaySql(), this.stack);
// in case of timeout, free accumulated rows
this._columns = null;
this._rows = [];
const err = packet.readError(info, opts.logParam ? this.displaySql() : this.sql, this.stack);
//force in transaction status, since query will have created a transaction if autocommit is off

@@ -139,3 +143,3 @@ //goal is to avoid unnecessary COMMIT/ROLLBACK.

const okPacket = new OkPacket(affectedRows, insertId, packet.readUInt16());
let mustRedirect = false;
if (info.status & ServerStatus.SESSION_STATE_CHANGED) {

@@ -167,2 +171,7 @@ packet.skipLengthCodedNumber();

case 'redirect_url':
mustRedirect = true;
info.redirect(value, this.okPacketSuccess.bind(this, okPacket, info));
break;
case 'connection_id':

@@ -187,3 +196,16 @@ info.threadId = parseInt(value);

}
if (!mustRedirect) {
if (
info.redirectRequest &&
(info.status & ServerStatus.STATUS_IN_TRANS) === 0 &&
(info.status & ServerStatus.MORE_RESULTS_EXISTS) === 0
) {
info.redirect(info.redirectRequest, this.okPacketSuccess.bind(this, okPacket, info));
} else {
this.okPacketSuccess(okPacket, info);
}
}
}
okPacketSuccess(okPacket, info) {
if (this._responseIndex === 0) {

@@ -220,3 +242,3 @@ // fast path for standard single result

this._columns = null;
this._rows = null;
this._rows = [];
}

@@ -374,3 +396,6 @@

info.status |= ServerStatus.STATUS_IN_TRANS;
return this.throwError(packet.readError(info, this.displaySql(), this.stack), info);
return this.throwError(
packet.readError(info, this.opts.logParam ? this.displaySql() : this.sql, this.stack),
info
);
}

@@ -389,43 +414,11 @@

if (this.opts.metaAsArray) {
//return promise object as array :
// example for SELECT 1 =>
// [
// [ {"1": 1} ], //rows
// [ColumnDefinition] //meta
// ]
if (info.status & ServerStatus.MORE_RESULTS_EXISTS || this.isOutParameter) {
if (!this._meta) this._meta = [];
this._meta[this._responseIndex] = this._columns;
this._responseIndex++;
return (this.onPacketReceive = this.readResponsePacket);
}
if (this._responseIndex === 0) {
this.success([this._rows[0], this._columns]);
} else {
if (!this._meta) this._meta = [];
this._meta[this._responseIndex] = this._columns;
this.success([this._rows, this._meta]);
}
if (
info.redirectRequest &&
(info.status & ServerStatus.STATUS_IN_TRANS) === 0 &&
(info.status & ServerStatus.MORE_RESULTS_EXISTS) === 0
) {
info.redirect(info.redirectRequest, this.resultSetEndingPacketResult.bind(this, info));
} else {
//return promise object as rows that have meta property :
// example for SELECT 1 =>
// [
// {"1": 1},
// meta: [ColumnDefinition]
// ]
Object.defineProperty(this._rows[this._responseIndex], 'meta', {
value: this._columns,
writable: true,
enumerable: this.opts.metaEnumerable
});
if (info.status & ServerStatus.MORE_RESULTS_EXISTS || this.isOutParameter) {
this._responseIndex++;
return (this.onPacketReceive = this.readResponsePacket);
}
this.success(this._responseIndex === 0 ? this._rows[0] : this._rows);
this.resultSetEndingPacketResult(info);
}
return;

@@ -438,2 +431,45 @@ }

resultSetEndingPacketResult(info) {
if (this.opts.metaAsArray) {
//return promise object as array :
// example for SELECT 1 =>
// [
// [ {"1": 1} ], //rows
// [ColumnDefinition] //meta
// ]
if (info.status & ServerStatus.MORE_RESULTS_EXISTS || this.isOutParameter) {
if (!this._meta) this._meta = [];
this._meta[this._responseIndex] = this._columns;
this._responseIndex++;
return (this.onPacketReceive = this.readResponsePacket);
}
if (this._responseIndex === 0) {
this.success([this._rows[0], this._columns]);
} else {
if (!this._meta) this._meta = [];
this._meta[this._responseIndex] = this._columns;
this.success([this._rows, this._meta]);
}
} else {
//return promise object as rows that have meta property :
// example for SELECT 1 =>
// [
// {"1": 1},
// meta: [ColumnDefinition]
// ]
Object.defineProperty(this._rows[this._responseIndex], 'meta', {
value: this._columns,
writable: true,
enumerable: this.opts.metaEnumerable
});
if (info.status & ServerStatus.MORE_RESULTS_EXISTS || this.isOutParameter) {
this._responseIndex++;
return (this.onPacketReceive = this.readResponsePacket);
}
this.success(this._responseIndex === 0 ? this._rows[0] : this._rows);
}
}
/**

@@ -451,3 +487,3 @@ * Display current SQL with parameters (truncated if too big)

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

@@ -460,4 +496,4 @@ if (this.sql.length > this.opts.debugLen) {

logParameters(sqlMsg, values) {
if (this.opts.namedPlaceholders) {
static logParameters(opts, sqlMsg, values) {
if (opts.namedPlaceholders) {
sqlMsg += '{';

@@ -474,5 +510,4 @@ let first = true;

sqlMsg = Parser.logParam(sqlMsg, param);
if (sqlMsg.length > this.opts.debugLen) {
sqlMsg = sqlMsg.substring(0, this.opts.debugLen) + '...';
break;
if (sqlMsg.length > opts.debugLen) {
return sqlMsg.substring(0, opts.debugLen) + '...';
}

@@ -488,5 +523,4 @@ }

sqlMsg = Parser.logParam(sqlMsg, param);
if (sqlMsg.length > this.opts.debugLen) {
sqlMsg = sqlMsg.substring(0, this.opts.debugLen) + '...';
break;
if (sqlMsg.length > opts.debugLen) {
return sqlMsg.substring(0, opts.debugLen) + '...';
}

@@ -496,4 +530,4 @@ }

sqlMsg = Parser.logParam(sqlMsg, values);
if (sqlMsg.length > this.opts.debugLen) {
sqlMsg = sqlMsg.substring(0, this.opts.debugLen) + '...';
if (sqlMsg.length > opts.debugLen) {
return sqlMsg.substring(0, opts.debugLen) + '...';
}

@@ -595,3 +629,3 @@ }

'22000',
this.sql
this.opts.logParam ? this.displaySql() : this.sql
);

@@ -605,15 +639,18 @@ error.cause = e;

stream.on('error', (err) => {
out.writeEmptyPacket();
const error = Errors.createError(
`LOCAL INFILE command failed: ${err.message}`,
Errors.ER_LOCAL_INFILE_NOT_READABLE,
info,
'22000',
this.sql
);
process.nextTick(this.reject, error);
this.reject = null;
this.resolve = null;
});
stream.on(
'error',
function (err) {
out.writeEmptyPacket();
const error = Errors.createError(
`LOCAL INFILE command failed: ${err.message}`,
Errors.ER_LOCAL_INFILE_NOT_READABLE,
info,
'22000',
this.sql
);
process.nextTick(this.reject, error);
this.reject = null;
this.resolve = null;
}.bind(this)
);
stream.on('data', (chunk) => {

@@ -620,0 +657,0 @@ out.writeBuffer(chunk, 0, chunk.length);

@@ -7,2 +7,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

const Command = require('./command');
const ServerStatus = require('../const/server-status');

@@ -43,3 +44,7 @@ const PING_COMMAND = new Uint8Array([1, 0, 0, 0, 0x0e]);

info.status = packet.readUInt16();
this.successEnd(null);
if (info.redirectRequest && (info.status & ServerStatus.STATUS_IN_TRANS) === 0) {
info.redirect(info.redirectRequest, this.successEnd.bind(this, null));
} else {
this.successEnd(null);
}
}

@@ -46,0 +51,0 @@ }

@@ -32,3 +32,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

start(out, opts, info) {
if (opts.logger.query) opts.logger.query(`QUERY: ${opts.logger.logParam ? this.displaySql() : this.sql}`);
if (opts.logger.query) opts.logger.query(`QUERY: ${opts.logParam ? this.displaySql() : this.sql}`);
this.onPacketReceive = this.readResponsePacket;

@@ -54,3 +54,3 @@ if (this.initialValues === undefined) {

this.initialValues,
this.displaySql.bind(this)
this.opts.logParam ? this.displaySql.bind(this) : () => this.sql
);

@@ -57,0 +57,0 @@ this.paramPositions = parsed.paramPositions;

@@ -7,2 +7,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

const Command = require('./command');
const ServerStatus = require('../const/server-status');
const RESET_COMMAND = new Uint8Array([1, 0, 0, 0, 0x1f]);

@@ -42,3 +43,7 @@ /**

info.status = packet.readUInt16();
this.successEnd();
if (info.redirectRequest && (info.status & ServerStatus.STATUS_IN_TRANS) === 0) {
info.redirect(info.redirectRequest, this.successEnd.bind(this));
} else {
this.successEnd();
}
}

@@ -45,0 +50,0 @@ }

@@ -39,3 +39,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

this.debugLen = opts.debugLen || 256;
this.logParam = opts.logParam === undefined ? true : opts.logParam === true;
if (opts.logger) {

@@ -47,4 +47,3 @@ if (typeof opts.logger === 'function') {

error: opts.logger,
warning: opts.logger,
logParam: true
warning: opts.logger
};

@@ -56,8 +55,8 @@ } else {

error: opts.logger.error,
warning: opts.logger.warning || console.log,
logParam: opts.logger.logParam == null ? true : opts.logger.logParam
warning: opts.logger.warning || console.log
};
if (opts.logger.logParam !== undefined) this.logParam = opts.logger.logParam;
}
} else {
this.logger = { network: null, query: null, error: null, warning: console.log, logParam: false };
this.logger = { network: null, query: null, error: null, warning: console.log };
if ((this.debug || this.debugCompress) && !this.logger.network) {

@@ -93,2 +92,3 @@ this.logger.network = console.log;

// connection options
this.permitRedirect = opts.permitRedirect === undefined ? true : opts.permitRedirect;
this.initSql = opts.initSql;

@@ -193,2 +193,4 @@ this.connectTimeout = opts.connectTimeout === undefined ? 1000 : opts.connectTimeout;

}
if (opts.permitRedirect) opts.permitRedirect = opts.permitRedirect === 'true';
if (opts.logParam) opts.logParam = opts.logParam === 'true';
if (opts.compress) opts.compress = opts.compress === 'true';

@@ -195,0 +197,0 @@ if (opts.connectAttributes) opts.connectAttributes = JSON.parse(opts.connectAttributes);

@@ -19,2 +19,3 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

const Capabilities = require('./const/capabilities');
const ConnectionOptions = require('./config/connection-options');

@@ -39,2 +40,3 @@ /*commands*/

const Collations = require('./const/collations');
const ConnOptions = require('./config/connection-options');

@@ -68,2 +70,3 @@ const convertFixedTime = function (tz, conn) {

};
const redirectUrlFormat = /(mariadb|mysql):\/\/(([^/@:]+)?(:([^/]+))?@)?(([^/:]+)(:([0-9]+))?)(\/([^?]+)(\?(.*))?)?$/;

@@ -99,3 +102,3 @@ /**

this.opts = Object.assign(new EventEmitter(), options);
this.info = new ConnectionInformation(this.opts);
this.info = new ConnectionInformation(this.opts, this.redirect.bind(this));
this.prepareCache =

@@ -184,3 +187,3 @@ this.opts.prepareCacheLength > 0 ? new LruPrepareCache(this.info, this.opts.prepareCacheLength) : null;

'HY000',
cmdParam.sql,
cmdParam.sql.length > this.opts.debugLen ? cmdParam.sql.substring(0, this.opts.debugLen) + '...' : cmdParam.sql,
false,

@@ -586,2 +589,8 @@ cmdParam.stack

// without connection being completely finished.
const bulkEnable =
_options === undefined || _options === null
? this.opts.bulk
: _options.bulk !== undefined && _options.bulk !== null
? _options.bulk
: this.opts.bulk;
if (

@@ -591,3 +600,3 @@ this.info.serverVersion &&

this.info.hasMinVersion(10, 2, 7) &&
this.opts.bulk &&
bulkEnable &&
(this.info.serverCapabilities & Capabilities.MARIADB_CLIENT_STMT_BULK_OPERATIONS) > 0n

@@ -1581,2 +1590,75 @@ ) {

/**
* Redirecting connection to server indicated value.
* @param value server host string
* @param resolve promise result when done
*/
redirect(value, resolve) {
if (this.opts.permitRedirect && value) {
// redirect only if :
// * when pipelining, having received all waiting responses.
// * not in a transaction
if (this.receiveQueue.length <= 1 && (this.info.status & ServerStatus.STATUS_IN_TRANS) === 0) {
this.info.redirectRequest = null;
const matchResults = value.match(redirectUrlFormat);
if (!matchResults) {
if (this.opts.logger.error)
this.opts.logger.error(
new Error(
`error parsing redirection string '${value}'. format must be 'mariadb/mysql://[<user>[:<password>]@]<host>[:<port>]/[<db>[?<opt1>=<value1>[&<opt2>=<value2>]]]'`
)
);
return resolve();
}
const options = {
host: matchResults[7] ? decodeURIComponent(matchResults[7]) : matchResults[6],
port: matchResults[9] ? parseInt(matchResults[9]) : 3306
};
// actually only options accepted are user and password
// there might be additional possible options in the future
if (matchResults[3]) options.user = matchResults[3];
if (matchResults[5]) options.password = matchResults[5];
const redirectOpts = ConnectionOptions.parseOptionDataType(options);
const finalRedirectOptions = new ConnOptions(Object.assign({}, this.opts, redirectOpts));
const conn = new Connection(finalRedirectOptions);
conn
.connect()
.then(
async function () {
const cmdParam = new CommandParameter();
await new Promise(this.end.bind(this, cmdParam));
this.status = Status.CONNECTED;
this.info = conn.info;
this.opts = conn.opts;
this.socket = conn.socket;
if (this.prepareCache) this.prepareCache.reset();
this.streamOut = conn.streamOut;
this.streamIn = conn.streamIn;
resolve();
}.bind(this)
)
.catch(
function (e) {
if (this.opts.logger.error) {
const err = new Error(`fail to redirect to '${value}'`);
err.cause = e;
this.opts.logger.error(err);
}
resolve();
}.bind(this)
);
} else {
this.info.redirectRequest = value;
resolve();
}
} else {
this.info.redirectRequest = null;
resolve();
}
}
get threadId() {

@@ -1583,0 +1665,0 @@ return this.info ? this.info.threadId : null;

@@ -458,9 +458,16 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

const len = this.buf[this.pos++];
const negate = this.buf[this.pos++] === 1;
const hour = this.readUInt32() * 24 + this.readUInt8();
const min = this.readUInt8();
const sec = this.readUInt8();
let negate = false;
let hour = 0;
let min = 0;
let sec = 0;
let microSec = 0;
if (len > 8) {
microSec = this.readUInt32();
if (len > 0) {
negate = this.buf[this.pos++] === 1;
hour = this.readUInt32() * 24 + this.readUInt8();
min = this.readUInt8();
sec = this.readUInt8();
if (len > 8) {
microSec = this.readUInt32();
}
}

@@ -467,0 +474,0 @@ let val = appendZero(hour, 2) + ':' + appendZero(min, 2) + ':' + appendZero(sec, 2);

@@ -7,3 +7,4 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

class ConnectionInformation {
constructor(opts) {
#redirectFct;
constructor(opts, redirectFct) {
this.threadId = -1;

@@ -14,2 +15,5 @@ this.status = null;

this.database = opts.database;
this.port = opts.port;
this.#redirectFct = redirectFct;
this.redirectRequest = null;
}

@@ -33,2 +37,6 @@

redirect(value, resolve) {
return this.#redirectFct(value, resolve);
}
isMariaDB() {

@@ -35,0 +43,0 @@ if (!this.serverVersion) throw new Error('cannot know if server is MariaDB until connection is established');

@@ -525,3 +525,11 @@ // SPDX-License-Identifier: LGPL-2.1-or-later

return Promise.reject(
Errors.createError('pool is closed', Errors.ER_POOL_ALREADY_CLOSED, null, 'HY000', null, false, cmdParam.stack)
Errors.createError(
'pool is closed',
Errors.ER_POOL_ALREADY_CLOSED,
null,
'HY000',
cmdParam === null ? null : cmdParam.sql,
false,
cmdParam.stack
)
);

@@ -542,3 +550,3 @@ }

'HY000',
null,
cmdParam === null ? null : cmdParam.sql,
false,

@@ -545,0 +553,0 @@ cmdParam.stack

{
"name": "mariadb",
"version": "3.2.2",
"version": "3.2.3",
"description": "fast mariadb or mysql connector.",

@@ -5,0 +5,0 @@ "main": "promise.js",

@@ -16,3 +16,3 @@ <p style="text-align: center;">

MariaDB and MySQL client, 100% JavaScript, with TypeScript definition, with the Promise API.
MariaDB and MySQL client, 100% JavaScript, with TypeScript definition, with the Promise API, distributed under the LGPL license version 2.1 or later (LGPL-2.1-or-later)

@@ -19,0 +19,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc