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 3.8.0 to 3.9.0

102

lib/parsers/binary_parser.js

@@ -83,9 +83,32 @@ 'use strict';

const parserFn = genFunc();
let i = 0;
const nullBitmapLength = Math.floor((fields.length + 7 + 2) / 8);
/* eslint-disable no-trailing-spaces */
/* eslint-disable no-spaced-func */
/* eslint-disable no-unexpected-multiline */
function wrap(field, packet) {
return {
type: typeNames[field.columnType],
length: field.columnLength,
db: field.schema,
table: field.table,
name: field.name,
string: function (encoding = field.encoding) {
if (field.columnType === Types.JSON && encoding === field.encoding) {
// Since for JSON columns mysql always returns charset 63 (BINARY),
// we have to handle it according to JSON specs and use "utf8",
// see https://github.com/sidorares/node-mysql2/issues/1661
console.warn(
`typeCast: JSON column "${field.name}" is interpreted as BINARY by default, recommended to manually set utf8 encoding: \`field.string("utf8")\``,
);
}
return packet.readLengthCodedString(encoding);
},
buffer: function () {
return packet.readLengthCodedBuffer();
},
geometry: function () {
return packet.parseGeometryValue();
},
};
}
parserFn('(function(){');

@@ -100,20 +123,15 @@ parserFn('return class BinaryRow {');

} else {
parserFn("const result = {};");
parserFn('const result = {};');
}
const resultTables = {};
let resultTablesArray = [];
if (options.nestTables === true) {
for (i = 0; i < fields.length; i++) {
resultTables[fields[i].table] = 1;
}
resultTablesArray = Object.keys(resultTables);
for (i = 0; i < resultTablesArray.length; i++) {
parserFn(`result[${helpers.srcEscape(resultTablesArray[i])}] = {};`);
}
// Global typeCast
if (
typeof config.typeCast === 'function' &&
typeof options.typeCast !== 'function'
) {
options.typeCast = config.typeCast;
}
parserFn('packet.readInt8();'); // status byte
for (i = 0; i < nullBitmapLength; ++i) {
for (let i = 0; i < nullBitmapLength; ++i) {
parserFn(`const nullBitmaskByte${i} = packet.readInt8();`);

@@ -128,3 +146,3 @@ }

for (i = 0; i < fields.length; i++) {
for (let i = 0; i < fields.length; i++) {
fieldName = helpers.srcEscape(fields[i].name);

@@ -134,8 +152,8 @@ parserFn(`// ${fieldName}: ${typeNames[fields[i].columnType]}`);

if (typeof options.nestTables === 'string') {
tableName = helpers.srcEscape(fields[i].table);
lvalue = `result[${helpers.srcEscape(
fields[i].table + options.nestTables + fields[i].name
fields[i].table + options.nestTables + fields[i].name,
)}]`;
} else if (options.nestTables === true) {
tableName = helpers.srcEscape(fields[i].table);
parserFn(`if (!result[${tableName}]) result[${tableName}] = {};`);
lvalue = `result[${tableName}][${fieldName}]`;

@@ -145,19 +163,25 @@ } else if (options.rowsAsArray) {

} else {
lvalue = `result[${helpers.srcEscape(fields[i].name)}]`;
lvalue = `result[${fieldName}]`;
}
// TODO: this used to be an optimisation ( if column marked as NOT_NULL don't include code to check null
// bitmap at all, but it seems that we can't rely on this flag, see #178
// TODO: benchmark performance difference
//
// if (fields[i].flags & FieldFlags.NOT_NULL) { // don't need to check null bitmap if field can't be null.
// result.push(lvalue + ' = ' + readCodeFor(fields[i], config));
// } else if (fields[i].columnType == Types.NULL) {
// result.push(lvalue + ' = null;');
// } else {
parserFn(`if (nullBitmaskByte${nullByteIndex} & ${currentFieldNullBit})`);
parserFn(`${lvalue} = null;`);
parserFn('else');
parserFn(`${lvalue} = ${readCodeFor(fields[i], config, options, i)}`);
// }
if (options.typeCast === false) {
parserFn(`${lvalue} = packet.readLengthCodedBuffer();`);
} else {
const fieldWrapperVar = `fieldWrapper${i}`;
parserFn(`const ${fieldWrapperVar} = wrap(fields[${i}], packet);`);
const readCode = readCodeFor(fields[i], config, options, i);
parserFn(`if (nullBitmaskByte${nullByteIndex} & ${currentFieldNullBit})`);
parserFn(`${lvalue} = null;`);
parserFn('else {');
if (typeof options.typeCast === 'function') {
parserFn(
`${lvalue} = options.typeCast(${fieldWrapperVar}, function() { return ${readCode} });`,
);
} else {
parserFn(`${lvalue} = ${readCode};`);
}
parserFn('}');
}
currentFieldNullBit *= 2;

@@ -174,13 +198,9 @@ if (currentFieldNullBit === 0x100) {

/* eslint-enable no-trailing-spaces */
/* eslint-enable no-spaced-func */
/* eslint-enable no-unexpected-multiline */
if (config.debug) {
helpers.printDebugWithCode(
'Compiled binary protocol row parser',
parserFn.toString()
parserFn.toString(),
);
}
return parserFn.toFunction();
return parserFn.toFunction({ wrap });
}

@@ -187,0 +207,0 @@

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

@@ -79,3 +79,3 @@ "main": "index.js",

"eslint-plugin-markdown": "^3.0.0",
"husky": "^8.0.2",
"husky": "^9.0.2",
"lint-staged": "^15.0.1",

@@ -82,0 +82,0 @@ "portfinder": "^1.0.28",

@@ -212,6 +212,2 @@ // This file was modified by Oracle on November 04, 2021.

* You can find which field function you need to use by looking at `RowDataPacket.prototype._typeCast`.
*
* ---
*
* For `execute`, please see: [typeCast not supported with .execute #649](https://github.com/sidorares/node-mysql2/issues/649).
*/

@@ -218,0 +214,0 @@ typeCast?: TypeCast;

@@ -73,6 +73,2 @@ import { Sequence } from './Sequence.js';

* You can find which field function you need to use by looking at `RowDataPacket.prototype._typeCast`.
*
* ---
*
* For `execute`, please see: [typeCast not supported with .execute #649](https://github.com/sidorares/node-mysql2/issues/649).
*/

@@ -79,0 +75,0 @@ typeCast?: TypeCast;

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