Socket
Socket
Sign inDemoInstall

mysql2

Package Overview
Dependencies
Maintainers
3
Versions
184
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql2 - npm Package Compare versions

Comparing version 2.3.0 to 2.3.1

5

lib/commands/command.js
'use strict';
const EventEmitter = require('events').EventEmitter;
const Timers = require('timers');

@@ -30,2 +31,6 @@ class Command extends EventEmitter {

err.sql = this.sql || this.query;
if (this.queryTimeout) {
Timers.clearTimeout(this.queryTimeout);
this.queryTimeout = null;
}
if (this.onResult) {

@@ -32,0 +37,0 @@ this.onResult(err);

4

lib/commands/execute.js

@@ -88,6 +88,6 @@ 'use strict';

}
this._rowParser = this.buildParserFromFields(
this._rowParser = new (this.buildParserFromFields(
this._fields[this._resultIndex],
connection
);
))();
return Execute.prototype.row;

@@ -94,0 +94,0 @@ }

@@ -12,3 +12,2 @@ 'use strict';

const ServerStatus = require('../constants/server_status.js');
const CharsetToEncoding = require('../constants/charset_encodings.js');

@@ -48,3 +47,4 @@ const EmptyPacket = new Packets.Packet(0, Buffer.allocUnsafe(4), 0, 4);

start(packet, connection) {
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
start(_packet, connection) {
if (connection.config.debug) {

@@ -217,3 +217,3 @@ // eslint-disable-next-line

this.emit('fields', fields);
this._rowParser = getTextParser(fields, this.options, connection.config);
this._rowParser = new (getTextParser(fields, this.options, connection.config))();
return Query.prototype.fieldsEOF;

@@ -232,3 +232,4 @@ }

row(packet) {
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
row(packet, _connection) {
if (packet.isEOF()) {

@@ -245,7 +246,6 @@ const status = packet.eofStatusFlags();

try {
row = new this._rowParser(
row = this._rowParser.next(
packet,
this._fields[this._resultIndex],
this.options,
CharsetToEncoding
this.options
);

@@ -252,0 +252,0 @@ } catch (err) {

@@ -48,4 +48,6 @@ 'use strict';

this.name = StringParser.decode(
this._buf.slice(_nameStart, _nameStart + _nameLength),
this.encoding === 'binary' ? this._clientEncoding : this.encoding
this._buf,
this.encoding === 'binary' ? this._clientEncoding : this.encoding,
_nameStart,
_nameStart + _nameLength
);

@@ -116,6 +118,17 @@ this.columnLength = packet.readInt32();

const end = start + this[`_${name}Length`];
return StringParser.decode(
this._buf.slice(start, end),
this.encoding === 'binary' ? this._clientEncoding : this.encoding
const val = StringParser.decode(
this._buf,
this.encoding === 'binary' ? this._clientEncoding : this.encoding,
start,
end
);
Object.defineProperty(this, name, {
value: val,
writable: false,
configurable: false,
enumerable: false
});
return val;
}

@@ -122,0 +135,0 @@ });

@@ -371,6 +371,8 @@ // This file was modified by Oracle on June 1, 2021.

}
// Format follows mySQL TIME format ([-][h]hh:mm:ss[.u[u[u[u[u[u]]]]]])
// For positive times below 24 hours, this makes it equal to ISO 8601 times
return (
(sign === -1 ? '-' : '') +
[d ? d * 24 + H : H, leftPad(2, M), leftPad(2, S)].join(':') +
(ms ? `.${ms}` : '')
[leftPad(2, d * 24 + H), leftPad(2, M), leftPad(2, S)].join(':') +
(ms ? `.${ms}`.replace(/0+$/, '') : '')
);

@@ -389,4 +391,6 @@ }

return StringParser.decode(
this.buffer.slice(this.offset - len, this.offset),
encoding
this.buffer,
encoding,
this.offset - len,
this.offset
);

@@ -410,3 +414,3 @@ }

this.offset = end + 1;
return StringParser.decode(this.buffer.slice(start, end), encoding);
return StringParser.decode(this.buffer, encoding, start, end);
}

@@ -416,5 +420,5 @@

readString(len, encoding) {
if ((typeof len === 'string') && (typeof encoding === 'undefined')) {
encoding = len
len = undefined
if (typeof len === 'string' && typeof encoding === 'undefined') {
encoding = len;
len = undefined;
}

@@ -426,4 +430,6 @@ if (typeof len === 'undefined') {

return StringParser.decode(
this.buffer.slice(this.offset - len, this.offset),
encoding
this.buffer,
encoding,
this.offset - len,
this.offset
);

@@ -907,3 +913,3 @@ }

static MockBuffer() {
const noop = function() {};
const noop = function () {};
const res = Buffer.alloc(0);

@@ -910,0 +916,0 @@ for (const op in NativeBuffer.prototype) {

@@ -77,3 +77,3 @@ 'use strict';

}
return `packet.readLengthCodedString(CharsetToEncoding[fields[${fieldNum}].characterSet])`;
return `packet.readLengthCodedString(fields[${fieldNum}].encoding)`;
}

@@ -91,8 +91,12 @@ }

parserFn('(function(){')(
'return function BinaryRow(packet, fields, options, CharsetToEncoding) {'
);
parserFn('(function(){');
parserFn('return class BinaryRow {');
parserFn('constructor() {');
parserFn('}');
parserFn('next(packet, fields, options) {');
if (options.rowsAsArray) {
parserFn(`const result = new Array(${fields.length});`);
} else {
parserFn("const result = {};");
}

@@ -109,3 +113,3 @@

for (i = 0; i < resultTablesArray.length; i++) {
parserFn(`this[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
parserFn(`result[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
}

@@ -131,3 +135,3 @@ }

tableName = helpers.srcEscape(fields[i].table);
lvalue = `this[${helpers.srcEscape(
lvalue = `result[${helpers.srcEscape(
fields[i].table + options.nestTables + fields[i].name

@@ -137,7 +141,7 @@ )}]`;

tableName = helpers.srcEscape(fields[i].table);
lvalue = `this[${tableName}][${fieldName}]`;
lvalue = `result[${tableName}][${fieldName}]`;
} else if (options.rowsAsArray) {
lvalue = `result[${i.toString(10)}]`;
} else {
lvalue = `this[${helpers.srcEscape(fields[i].name)}]`;
lvalue = `result[${helpers.srcEscape(fields[i].name)}]`;
}

@@ -166,6 +170,4 @@

if (options.rowsAsArray) {
parserFn('return result;');
}
parserFn('return result;');
parserFn('}');
parserFn('};')('})()');

@@ -172,0 +174,0 @@

@@ -23,9 +23,3 @@ 'use strict';

const field = fields[i];
res += `/${field.name}:${field.columnType}:${field.flags}:${
field.characterSet
}`;
if (options.nestTables) {
res += `:${field.table}`
}
res += `/${field.name}:${field.columnType}:${field.length}:${field.schema}:${field.table}:${field.flags}:${field.characterSet}`;
}

@@ -32,0 +26,0 @@ return res;

@@ -5,5 +5,5 @@ 'use strict';

exports.decode = function(buffer, encoding, options) {
exports.decode = function(buffer, encoding, start, end, options) {
if (Buffer.isEncoding(encoding)) {
return buffer.toString(encoding);
return buffer.toString(encoding, start, end);
}

@@ -13,3 +13,3 @@

const res = decoder.write(buffer);
const res = decoder.write(buffer.slice(start, end));
const trail = decoder.end();

@@ -16,0 +16,0 @@

@@ -73,23 +73,2 @@ 'use strict';

function compile(fields, options, config) {
// node-mysql typeCast compatibility wrapper
// see https://github.com/mysqljs/mysql/blob/96fdd0566b654436624e2375c7b6604b1f50f825/lib/protocol/packets/Field.js
function wrap(field, type, packet, encoding) {
return {
type: type,
length: field.columnLength,
db: field.schema,
table: field.table,
name: field.name,
string: function() {
return packet.readLengthCodedString(encoding);
},
buffer: function() {
return packet.readLengthCodedBuffer();
},
geometry: function() {
return packet.parseGeometryValue();
}
};
}
// use global typeCast if current query doesn't specify one

@@ -104,3 +83,2 @@ if (

const parserFn = genFunc();
let i = 0;

@@ -111,11 +89,51 @@ /* eslint-disable no-trailing-spaces */

parserFn('(function () {')(
'return function TextRow(packet, fields, options, CharsetToEncoding) {'
'return class TextRow {'
);
if (options.rowsAsArray) {
parserFn(`const result = new Array(${fields.length})`);
// constructor method
parserFn('constructor() {');
// node-mysql typeCast compatibility wrapper
// see https://github.com/mysqljs/mysql/blob/96fdd0566b654436624e2375c7b6604b1f50f825/lib/protocol/packets/Field.js
if (typeof options.typeCast === 'function') {
parserFn('const _this = this;');
for(let i=0; i<fields.length; ++i) {
const field = fields[i];
const encodingExpr = helpers.srcEscape(field.encoding);
const readCode = readCodeFor(
fields[i].columnType,
fields[i].characterSet,
encodingExpr,
config,
options
);
parserFn(`this.wrap${i} = {
type: ${helpers.srcEscape(typeNames[field.columnType])},
length: ${helpers.srcEscape(field.columnLength)},
db: ${helpers.srcEscape(field.schema)},
table: ${helpers.srcEscape(field.table)},
name: ${helpers.srcEscape(field.name)},
string: function() {
return _this.packet.readLengthCodedString(${encodingExpr});
},
buffer: function() {
return _this.packet.readLengthCodedBuffer();
},
geometry: function() {
return _this.packet.parseGeometryValue();
},
readNext: function() {
return _this.${readCode};
}
};`);
}
}
parserFn('}');
if (typeof options.typeCast === 'function') {
parserFn(`const wrap = ${wrap.toString()}`);
// next method
parserFn('next(packet, fields, options) {');
parserFn("this.packet = packet;");
if (options.rowsAsArray) {
parserFn(`const result = new Array(${fields.length});`);
} else {
parserFn("const result = {};");
}

@@ -127,8 +145,8 @@

if (options.nestTables === true) {
for (i = 0; i < fields.length; i++) {
for (let i=0; i < fields.length; i++) {
resultTables[fields[i].table] = 1;
}
resultTablesArray = Object.keys(resultTables);
for (i = 0; i < resultTablesArray.length; i++) {
parserFn(`this[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
for (let i=0; i < resultTablesArray.length; i++) {
parserFn(`result[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
}

@@ -139,33 +157,29 @@ }

let fieldName = '';
for (i = 0; i < fields.length; i++) {
for (let i = 0; i < fields.length; i++) {
fieldName = helpers.srcEscape(fields[i].name);
parserFn(`// ${fieldName}: ${typeNames[fields[i].columnType]}`);
if (typeof options.nestTables === 'string') {
lvalue = `this[${helpers.srcEscape(
lvalue = `result[${helpers.srcEscape(
fields[i].table + options.nestTables + fields[i].name
)}]`;
} else if (options.nestTables === true) {
lvalue = `this[${helpers.srcEscape(fields[i].table)}][${fieldName}]`;
lvalue = `result[${helpers.srcEscape(fields[i].table)}][${fieldName}]`;
} else if (options.rowsAsArray) {
lvalue = `result[${i.toString(10)}]`;
} else {
lvalue = `this[${fieldName}]`;
lvalue = `result[${fieldName}]`;
}
const encodingExpr = `CharsetToEncoding[fields[${i}].characterSet]`;
const readCode = readCodeFor(
fields[i].columnType,
fields[i].characterSet,
encodingExpr,
config,
options
);
if (typeof options.typeCast === 'function') {
parserFn(
`${lvalue} = options.typeCast(wrap(fields[${i}], ${helpers.srcEscape(
typeNames[fields[i].columnType]
)}, packet, ${encodingExpr}), function() { return ${readCode};})`
);
parserFn(`${lvalue} = options.typeCast(this.wrap${i}, this.wrap${i}.readNext);`);
} else if (options.typeCast === false) {
parserFn(`${lvalue} = packet.readLengthCodedBuffer();`);
} else {
const encodingExpr = `fields[${i}].encoding`;
const readCode = readCodeFor(
fields[i].columnType,
fields[i].characterSet,
encodingExpr,
config,
options
);
parserFn(`${lvalue} = ${readCode};`);

@@ -175,6 +189,4 @@ }

if (options.rowsAsArray) {
parserFn('return result;');
}
parserFn('return result;');
parserFn('}');
parserFn('};')('})()');

@@ -181,0 +193,0 @@

{
"name": "mysql2",
"version": "2.3.0",
"version": "2.3.1",
"description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",

@@ -13,7 +13,6 @@ "main": "index.js",

"lint:docs": "eslint Contributing.md \"documentation/**/*.md\" \"examples/*.js\"",
"test": "npm run lint && npm run test:raw",
"test:raw": "node ./test/run.js",
"test": "node ./test/run.js",
"benchmark": "./benchmarks/run-unit.js",
"prettier": "prettier --single-quote --trailing-comma none --write \"{lib,examples,test}/**/*.js\"",
"prettier:docs": "prettier-markdown README.md documentation/*",
"prettier:docs": "prettier --single-quote --trailing-comma none --write README.md documentation/*",
"precommit": "lint-staged",

@@ -57,5 +56,5 @@ "eslint-check": "eslint --print-config .eslintrc | eslint-config-prettier-check",

"dependencies": {
"denque": "^1.4.1",
"denque": "^2.0.1",
"generate-function": "^2.3.1",
"iconv-lite": "^0.6.2",
"iconv-lite": "^0.6.3",
"long": "^4.0.0",

@@ -68,18 +67,18 @@ "lru-cache": "^6.0.0",

"devDependencies": {
"assert-diff": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^2.3.2",
"@typescript-eslint/parser": "^2.3.2",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"assert-diff": "^3.0.2",
"benchmark": "^2.1.4",
"error-stack-parser": "^2.0.3",
"eslint": "^6.2.2",
"eslint-config-prettier": "^6.1.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-async-await": "0.0.0",
"eslint-plugin-markdown": "^1.0.0",
"husky": "^3.0.4",
"eslint-plugin-markdown": "^2.2.1",
"husky": "^7.0.2",
"is-async-supported": "^1.2.0",
"lint-staged": "^10.0.3",
"lint-staged": "^11.2.0",
"portfinder": "^1.0.28",
"prettier": "^2.0.5",
"prettier-markdown": "^0.1.6",
"prettier": "^2.4.1",
"progress": "^2.0.3",
"typescript": "^3.6.3",
"typescript": "^4.4.3",
"urun": "0.0.8",

@@ -86,0 +85,0 @@ "utest": "0.0.8"

@@ -12,4 +12,5 @@

warningStatus: number;
changedRows?: number;
}
export = ResultSetHeader;

Sorry, the diff of this file is too big to display

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