@depup/mysql2 3.22.0-depup.0 → 3.23.2-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/changes.json +8 -3
- package/lib/base/connection.js +4 -2
- package/lib/base/pool.js +4 -0
- package/lib/commands/client_handshake.js +26 -2
- package/lib/commands/execute.js +17 -4
- package/lib/commands/ping.js +1 -1
- package/lib/commands/prepare.js +10 -2
- package/lib/commands/query.js +2 -1
- package/lib/compressed_protocol.js +1 -1
- package/lib/connection_config.js +1 -0
- package/lib/constants/charset_encodings.js +25 -1
- package/lib/constants/mariadb_client.js +19 -0
- package/lib/packets/binary_row.js +2 -2
- package/lib/packets/binlog_query_statusvars.js +1 -1
- package/lib/packets/change_user.js +1 -1
- package/lib/packets/column_definition.js +35 -1
- package/lib/packets/encode_parameter.js +12 -2
- package/lib/packets/execute.js +8 -2
- package/lib/packets/handshake.js +13 -1
- package/lib/packets/handshake_response.js +5 -1
- package/lib/packets/packet.js +51 -3
- package/lib/packets/resultset_header.js +1 -1
- package/lib/packets/ssl_request.js +6 -1
- package/lib/packets/text_row.js +1 -1
- package/lib/parsers/binary_parser.js +45 -6
- package/lib/parsers/parser_cache.js +3 -0
- package/lib/parsers/static_binary_parser.js +37 -2
- package/lib/parsers/static_text_parser.js +21 -2
- package/lib/parsers/text_parser.js +15 -9
- package/lib/promise/capture_local_err.js +25 -0
- package/lib/promise/connection.js +35 -40
- package/lib/promise/make_done_cb.js +5 -9
- package/lib/promise/pool.js +11 -9
- package/lib/promise/pool_cluster.js +9 -2
- package/lib/promise/prepared_statement_info.js +5 -1
- package/package.json +13 -8
- package/promise.js +16 -15
- package/typings/mysql/lib/Connection.d.ts +7 -1
- package/typings/mysql/lib/parsers/typeCast.d.ts +11 -0
- package/typings/mysql/lib/protocol/packets/FieldPacket.d.ts +11 -0
- package/typings/mysql/lib/protocol/sequences/Query.d.ts +7 -1
package/README.md
CHANGED
|
@@ -13,10 +13,16 @@ npm install @depup/mysql2
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [mysql2](https://www.npmjs.com/package/mysql2) @ 3.
|
|
17
|
-
| Processed | 2026-
|
|
16
|
+
| Original | [mysql2](https://www.npmjs.com/package/mysql2) @ 3.23.2 |
|
|
17
|
+
| Processed | 2026-07-27 |
|
|
18
18
|
| Smoke test | passed |
|
|
19
|
-
| Deps updated |
|
|
19
|
+
| Deps updated | 1 |
|
|
20
|
+
|
|
21
|
+
## Dependency Changes
|
|
22
|
+
|
|
23
|
+
| Dependency | From | To |
|
|
24
|
+
|------------|------|-----|
|
|
25
|
+
| iconv-lite | ^0.7.2 | ^0.7.3 |
|
|
20
26
|
|
|
21
27
|
---
|
|
22
28
|
|
package/changes.json
CHANGED
package/lib/base/connection.js
CHANGED
|
@@ -87,6 +87,8 @@ class BaseConnection extends EventEmitter {
|
|
|
87
87
|
},
|
|
88
88
|
});
|
|
89
89
|
this.serverCapabilityFlags = 0;
|
|
90
|
+
this._isMariaDB = false;
|
|
91
|
+
this._mariadbExtendedMetadata = false;
|
|
90
92
|
this.authorized = false;
|
|
91
93
|
this.sequenceId = 0;
|
|
92
94
|
this.compressedSequenceId = 0;
|
|
@@ -186,7 +188,7 @@ class BaseConnection extends EventEmitter {
|
|
|
186
188
|
});
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
|
-
// in case there was no initial handshake but we need to read
|
|
191
|
+
// in case there was no initial handshake but we need to read string, assume it utf-8
|
|
190
192
|
// most common example: "Too many connections" error ( packet is sent immediately on connection attempt, we don't know server encoding yet)
|
|
191
193
|
// will be overwritten with actual encoding value as soon as server handshake packet is received
|
|
192
194
|
this.serverEncoding = 'utf8';
|
|
@@ -285,7 +287,7 @@ class BaseConnection extends EventEmitter {
|
|
|
285
287
|
bubbleErrorToConnection = true;
|
|
286
288
|
}
|
|
287
289
|
}
|
|
288
|
-
// notify connection if some
|
|
290
|
+
// notify connection if some commands in the queue did not have callbacks
|
|
289
291
|
// or if this is pool connection ( so it can be removed from pool )
|
|
290
292
|
if (bubbleErrorToConnection || this._pool) {
|
|
291
293
|
this.emit('error', err);
|
package/lib/base/pool.js
CHANGED
|
@@ -185,6 +185,10 @@ class BasePool extends EventEmitter {
|
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
|
+
while (this._connectionQueue.length > 0) {
|
|
189
|
+
const queuedCallback = this._connectionQueue.shift();
|
|
190
|
+
process.nextTick(() => queuedCallback(new Error('Pool is closed.')));
|
|
191
|
+
}
|
|
188
192
|
let calledBack = false;
|
|
189
193
|
let closedConnections = 0;
|
|
190
194
|
let connection;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// This file was modified by Oracle on June 17, 2021.
|
|
2
|
-
// Handshake errors are now
|
|
2
|
+
// Handshake errors are now marked as fatal and the corresponding events are
|
|
3
3
|
// emitted in the command instance itself.
|
|
4
4
|
// Modifications copyright (c) 2021, Oracle and/or its affiliates.
|
|
5
5
|
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
const Command = require('./command.js');
|
|
14
14
|
const Packets = require('../packets/index.js');
|
|
15
15
|
const ClientConstants = require('../constants/client.js');
|
|
16
|
+
const MariaDBClientConstants = require('../constants/mariadb_client.js');
|
|
16
17
|
const CharsetToEncoding = require('../constants/charset_encodings.js');
|
|
17
18
|
const auth41 = require('../auth_41.js');
|
|
18
19
|
const { getAuthPlugin } = require('./auth_switch.js');
|
|
@@ -35,6 +36,7 @@ class ClientHandshake extends Command {
|
|
|
35
36
|
super();
|
|
36
37
|
this.handshake = null;
|
|
37
38
|
this.clientFlags = clientFlags;
|
|
39
|
+
this.mariadbExtendedClientFlags = 0;
|
|
38
40
|
this.authenticationFactor = 0;
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -45,7 +47,8 @@ class ClientHandshake extends Command {
|
|
|
45
47
|
sendSSLRequest(connection) {
|
|
46
48
|
const sslRequest = new Packets.SSLRequest(
|
|
47
49
|
this.clientFlags,
|
|
48
|
-
connection.config.charsetNumber
|
|
50
|
+
connection.config.charsetNumber,
|
|
51
|
+
this.mariadbExtendedClientFlags
|
|
49
52
|
);
|
|
50
53
|
connection.writePacket(sslRequest.toPacket());
|
|
51
54
|
}
|
|
@@ -130,6 +133,7 @@ class ClientHandshake extends Command {
|
|
|
130
133
|
|
|
131
134
|
const handshakeResponse = new Packets.HandshakeResponse({
|
|
132
135
|
flags: this.clientFlags,
|
|
136
|
+
mariadbExtendedClientFlags: this.mariadbExtendedClientFlags,
|
|
133
137
|
user: this.user,
|
|
134
138
|
database: this.database,
|
|
135
139
|
password: this.password,
|
|
@@ -265,6 +269,26 @@ class ClientHandshake extends Command {
|
|
|
265
269
|
connection.serverCapabilityFlags = this.handshake.capabilityFlags;
|
|
266
270
|
connection.serverEncoding = CharsetToEncoding[this.handshake.characterSet];
|
|
267
271
|
connection.connectionId = this.handshake.connectionId;
|
|
272
|
+
// MariaDB needs a few protocol deviations, e.g. it rejects the JSON
|
|
273
|
+
// parameter type in COM_STMT_EXECUTE
|
|
274
|
+
connection._isMariaDB = /mariadb/i.test(this.handshake.serverVersion);
|
|
275
|
+
// If a MariaDB server offers extended column metadata, request it so
|
|
276
|
+
// MariaDB-specific column types (UUID, INET4, INET6, VECTOR and the JSON
|
|
277
|
+
// alias) can be identified. The server only reads the extended client
|
|
278
|
+
// capability bytes when the client leaves CLIENT_MYSQL (LONG_PASSWORD)
|
|
279
|
+
// unset, mirroring the server side of the negotiation.
|
|
280
|
+
if (
|
|
281
|
+
this.handshake.mariadbExtendedCapabilityFlags &
|
|
282
|
+
MariaDBClientConstants.MARIADB_CLIENT_EXTENDED_METADATA
|
|
283
|
+
) {
|
|
284
|
+
this.clientFlags &= ~ClientConstants.LONG_PASSWORD;
|
|
285
|
+
this.mariadbExtendedClientFlags |=
|
|
286
|
+
MariaDBClientConstants.MARIADB_CLIENT_EXTENDED_METADATA;
|
|
287
|
+
}
|
|
288
|
+
connection._mariadbExtendedMetadata = Boolean(
|
|
289
|
+
this.mariadbExtendedClientFlags &
|
|
290
|
+
MariaDBClientConstants.MARIADB_CLIENT_EXTENDED_METADATA
|
|
291
|
+
);
|
|
268
292
|
const serverSSLSupport =
|
|
269
293
|
this.handshake.capabilityFlags & ClientConstants.SSL;
|
|
270
294
|
// multi factor authentication is enabled with the
|
package/lib/commands/execute.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const Timers = require('timers');
|
|
4
|
+
|
|
3
5
|
const Command = require('./command.js');
|
|
4
6
|
const Query = require('./query.js');
|
|
5
7
|
const Packets = require('../packets/index.js');
|
|
@@ -51,7 +53,8 @@ class Execute extends Command {
|
|
|
51
53
|
connection.config.charsetNumber,
|
|
52
54
|
connection.config.timezone,
|
|
53
55
|
this._executeOptions.attributes,
|
|
54
|
-
clientFlags
|
|
56
|
+
clientFlags,
|
|
57
|
+
connection._isMariaDB
|
|
55
58
|
);
|
|
56
59
|
//For reasons why this try-catch is here, please see
|
|
57
60
|
// https://github.com/sidorares/node-mysql2/pull/689
|
|
@@ -62,7 +65,16 @@ class Execute extends Command {
|
|
|
62
65
|
try {
|
|
63
66
|
connection.writePacket(executePacket.toPacket(1));
|
|
64
67
|
} catch (error) {
|
|
65
|
-
this.
|
|
68
|
+
if (this.queryTimeout) {
|
|
69
|
+
Timers.clearTimeout(this.queryTimeout);
|
|
70
|
+
this.queryTimeout = null;
|
|
71
|
+
}
|
|
72
|
+
if (this.onResult) {
|
|
73
|
+
this.onResult(error);
|
|
74
|
+
} else {
|
|
75
|
+
this.emit('error', error);
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
66
78
|
}
|
|
67
79
|
return Execute.prototype.resultsetHeader;
|
|
68
80
|
}
|
|
@@ -72,12 +84,13 @@ class Execute extends Command {
|
|
|
72
84
|
// disabling for now, but would be great to find reliable way to parse fields only once
|
|
73
85
|
// fields reported by prepare can be empty at all or just incorrect - see #169
|
|
74
86
|
//
|
|
75
|
-
//
|
|
87
|
+
// performance optimisation: if we already have this field parsed in statement header, use one from header
|
|
76
88
|
// const field = this.statement.columns.length == this._fieldCount ?
|
|
77
89
|
// this.statement.columns[this._receivedFieldsCount] : new Packets.ColumnDefinition(packet);
|
|
78
90
|
const field = new Packets.ColumnDefinition(
|
|
79
91
|
packet,
|
|
80
|
-
connection.clientEncoding
|
|
92
|
+
connection.clientEncoding,
|
|
93
|
+
connection._mariadbExtendedMetadata
|
|
81
94
|
);
|
|
82
95
|
this._receivedFieldsCount++;
|
|
83
96
|
this._fields[this._resultIndex].push(field);
|
package/lib/commands/ping.js
CHANGED
|
@@ -5,7 +5,7 @@ const CommandCode = require('../constants/commands');
|
|
|
5
5
|
const Packet = require('../packets/packet');
|
|
6
6
|
|
|
7
7
|
// TODO: time statistics?
|
|
8
|
-
//
|
|
8
|
+
// useful for queue size and network latency monitoring
|
|
9
9
|
// store created,sent,reply timestamps
|
|
10
10
|
class Ping extends Command {
|
|
11
11
|
constructor(callback) {
|
package/lib/commands/prepare.js
CHANGED
|
@@ -87,7 +87,11 @@ class Prepare extends Command {
|
|
|
87
87
|
}
|
|
88
88
|
return this.prepareDone(connection);
|
|
89
89
|
}
|
|
90
|
-
const def = new Packets.ColumnDefinition(
|
|
90
|
+
const def = new Packets.ColumnDefinition(
|
|
91
|
+
packet,
|
|
92
|
+
connection.clientEncoding,
|
|
93
|
+
connection._mariadbExtendedMetadata
|
|
94
|
+
);
|
|
91
95
|
this.parameterDefinitions.push(def);
|
|
92
96
|
if (this.parameterDefinitions.length === this.parameterCount) {
|
|
93
97
|
return Prepare.prototype.parametersEOF;
|
|
@@ -99,7 +103,11 @@ class Prepare extends Command {
|
|
|
99
103
|
if (packet.isEOF()) {
|
|
100
104
|
return this.prepareDone(connection);
|
|
101
105
|
}
|
|
102
|
-
const def = new Packets.ColumnDefinition(
|
|
106
|
+
const def = new Packets.ColumnDefinition(
|
|
107
|
+
packet,
|
|
108
|
+
connection.clientEncoding,
|
|
109
|
+
connection._mariadbExtendedMetadata
|
|
110
|
+
);
|
|
103
111
|
this.fields.push(def);
|
|
104
112
|
if (this.fields.length === this.fieldCount) {
|
|
105
113
|
return Prepare.prototype.fieldsEOF;
|
package/lib/commands/query.js
CHANGED
|
@@ -199,7 +199,8 @@ class Query extends Command {
|
|
|
199
199
|
if (this._fields[this._resultIndex].length !== this._fieldCount) {
|
|
200
200
|
const field = new Packets.ColumnDefinition(
|
|
201
201
|
packet,
|
|
202
|
-
connection.clientEncoding
|
|
202
|
+
connection.clientEncoding,
|
|
203
|
+
connection._mariadbExtendedMetadata
|
|
203
204
|
);
|
|
204
205
|
this._fields[this._resultIndex].push(field);
|
|
205
206
|
if (connection.config.debug) {
|
|
@@ -40,7 +40,7 @@ function handleCompressedPacket(packet) {
|
|
|
40
40
|
|
|
41
41
|
if (deflatedLength !== 0) {
|
|
42
42
|
connection.inflateQueue.push((task) => {
|
|
43
|
-
zlib.inflate(body, (err, data) => {
|
|
43
|
+
zlib.inflate(body, { maxOutputLength: deflatedLength }, (err, data) => {
|
|
44
44
|
if (err) {
|
|
45
45
|
connection._handleNetworkError(err);
|
|
46
46
|
return;
|
package/lib/connection_config.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// see tools/generate-charset-mapping.js
|
|
4
4
|
// basicalliy result of "SHOW COLLATION" query
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const encodings = [
|
|
7
7
|
'utf8',
|
|
8
8
|
'big5',
|
|
9
9
|
'latin2',
|
|
@@ -315,3 +315,27 @@ module.exports = [
|
|
|
315
315
|
'utf8',
|
|
316
316
|
'utf8',
|
|
317
317
|
];
|
|
318
|
+
|
|
319
|
+
// MariaDB NO PAD collations mirror their PAD SPACE counterparts:
|
|
320
|
+
// collation id = PAD SPACE collation id + 1024
|
|
321
|
+
const padSpaceLength = encodings.length;
|
|
322
|
+
for (let id = 1025; id < 1024 + padSpaceLength; id++) {
|
|
323
|
+
encodings[id] = encodings[id - 1024];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// MariaDB UCA-14.0.0 (uca1400) collations use fixed 256-id blocks
|
|
327
|
+
// per character set, each covering the PAD SPACE and NO PAD variants
|
|
328
|
+
const uca1400Blocks = [
|
|
329
|
+
[2048, 'cesu8'], // utf8mb3
|
|
330
|
+
[2304, 'utf8'], // utf8mb4
|
|
331
|
+
[2560, 'ucs2'], // ucs2
|
|
332
|
+
[2816, 'utf16'], // utf16
|
|
333
|
+
[3072, 'utf32'], // utf32
|
|
334
|
+
];
|
|
335
|
+
for (const [start, encoding] of uca1400Blocks) {
|
|
336
|
+
for (let id = start; id < start + 256; id++) {
|
|
337
|
+
encodings[id] = encoding;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
module.exports = encodings;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// MariaDB-specific extended capability flags.
|
|
4
|
+
//
|
|
5
|
+
// MariaDB servers (10.2+) do not set the CLIENT_MYSQL (LONG_PASSWORD)
|
|
6
|
+
// capability and instead use 4 reserved bytes of the initial handshake packet
|
|
7
|
+
// to advertise these flags. Clients answer with their own extended
|
|
8
|
+
// capabilities in the last 4 reserved bytes of the handshake response
|
|
9
|
+
// (the server only reads them when the client leaves CLIENT_MYSQL unset).
|
|
10
|
+
//
|
|
11
|
+
// The flags below are the lower 32 bits shifted down, i.e.
|
|
12
|
+
// MARIADB_CLIENT_PROGRESS is documented as 1 << 32.
|
|
13
|
+
// https://mariadb.com/docs/server/reference/clientserver-protocol/1-connecting/connection
|
|
14
|
+
exports.MARIADB_CLIENT_PROGRESS = 0x00000001;
|
|
15
|
+
exports.MARIADB_CLIENT_COM_MULTI = 0x00000002; /* deprecated */
|
|
16
|
+
exports.MARIADB_CLIENT_STMT_BULK_OPERATIONS = 0x00000004;
|
|
17
|
+
exports.MARIADB_CLIENT_EXTENDED_METADATA = 0x00000008;
|
|
18
|
+
exports.MARIADB_CLIENT_CACHE_METADATA = 0x00000010;
|
|
19
|
+
exports.MARIADB_CLIENT_BULK_UNIT_RESULTS = 0x00000020;
|
|
@@ -12,7 +12,7 @@ class BinaryRow {
|
|
|
12
12
|
|
|
13
13
|
static toPacket(columns, encoding) {
|
|
14
14
|
// throw new Error('Not implemented');
|
|
15
|
-
const sequenceId = 0; // TODO remove, this is calculated now in
|
|
15
|
+
const sequenceId = 0; // TODO remove, this is calculated now in connection
|
|
16
16
|
let length = 0;
|
|
17
17
|
columns.forEach((val) => {
|
|
18
18
|
if (val === null || typeof val === 'undefined') {
|
|
@@ -82,7 +82,7 @@ binaryReader[2] = Packet.prototype.readInt16; // short
|
|
|
82
82
|
binaryReader[3] = Packet.prototype.readInt32; // long
|
|
83
83
|
binaryReader[4] = Packet.prototype.readFloat; // float
|
|
84
84
|
binaryReader[5] = Packet.prototype.readDouble; // double
|
|
85
|
-
binaryReader[6] = Packet.prototype.assertInvalid; // null, should be skipped
|
|
85
|
+
binaryReader[6] = Packet.prototype.assertInvalid; // null, should be skipped via null bitmap
|
|
86
86
|
binaryReader[7] = Packet.prototype.readTimestamp; // timestamp, http://dev.mysql.com/doc/internals/en/prepared-statements.html#packet-ProtocolBinary::MYSQL_TYPE_TIMESTAMP
|
|
87
87
|
binaryReader[8] = Packet.prototype.readInt64; // long long
|
|
88
88
|
binaryReader[9] = Packet.prototype.readInt32; // int24
|
|
@@ -31,7 +31,7 @@ module.exports = function parseStatusVars(buffer) {
|
|
|
31
31
|
offset += 4;
|
|
32
32
|
break;
|
|
33
33
|
case keys.SQL_MODE:
|
|
34
|
-
// value is 8 bytes, but all
|
|
34
|
+
// value is 8 bytes, but all documented flags are in first 4 bytes
|
|
35
35
|
result.sqlMode = buffer.readUInt32LE(offset);
|
|
36
36
|
offset += 8;
|
|
37
37
|
break;
|
|
@@ -16,7 +16,7 @@ class ChangeUser {
|
|
|
16
16
|
this.passwordSha1 = opts.passwordSha1;
|
|
17
17
|
this.authPluginData1 = opts.authPluginData1;
|
|
18
18
|
this.authPluginData2 = opts.authPluginData2;
|
|
19
|
-
this.connectAttributes = opts.
|
|
19
|
+
this.connectAttributes = opts.connectAttributes || {};
|
|
20
20
|
let authToken;
|
|
21
21
|
if (this.passwordSha1) {
|
|
22
22
|
authToken = auth41.calculateTokenFromPasswordSha(
|
|
@@ -19,7 +19,7 @@ const fields = ['catalog', 'schema', 'table', 'orgTable', 'name', 'orgName'];
|
|
|
19
19
|
// see https://github.com/sidorares/node-mysql2/pull/137
|
|
20
20
|
//
|
|
21
21
|
class ColumnDefinition {
|
|
22
|
-
constructor(packet, clientEncoding) {
|
|
22
|
+
constructor(packet, clientEncoding, mariadbExtendedMetadata) {
|
|
23
23
|
this._buf = packet.buffer;
|
|
24
24
|
this._clientEncoding = clientEncoding;
|
|
25
25
|
this._catalogLength = packet.readLengthCodedNumber();
|
|
@@ -41,6 +41,14 @@ class ColumnDefinition {
|
|
|
41
41
|
this._orgNameLength = packet.readLengthCodedNumber();
|
|
42
42
|
this._orgNameStart = packet.offset;
|
|
43
43
|
packet.offset += this._orgNameLength;
|
|
44
|
+
// MariaDB-specific column types (UUID, INET4, INET6, VECTOR and the JSON
|
|
45
|
+
// alias) are sent as standard string/blob types on the wire; the real
|
|
46
|
+
// type is only visible here, in the extended metadata block negotiated
|
|
47
|
+
// via the MARIADB_CLIENT_EXTENDED_METADATA capability (parsed out of
|
|
48
|
+
// line and with prototype defaults to keep this hot constructor small)
|
|
49
|
+
if (mariadbExtendedMetadata) {
|
|
50
|
+
this._parseMariadbExtendedMetadata(packet);
|
|
51
|
+
}
|
|
44
52
|
packet.skip(1); // length of the following fields (always 0x0c)
|
|
45
53
|
this.characterSet = packet.readInt16();
|
|
46
54
|
this.encoding = CharsetToEncoding[this.characterSet];
|
|
@@ -57,6 +65,27 @@ class ColumnDefinition {
|
|
|
57
65
|
this.decimals = packet.readInt8();
|
|
58
66
|
}
|
|
59
67
|
|
|
68
|
+
_parseMariadbExtendedMetadata(packet) {
|
|
69
|
+
// length-encoded block of { int<1> id, string<lenenc> value } pairs
|
|
70
|
+
const extendedMetadataLength = packet.readLengthCodedNumber() || 0;
|
|
71
|
+
const extendedMetadataEnd = Math.min(
|
|
72
|
+
packet.offset + extendedMetadataLength,
|
|
73
|
+
packet.end
|
|
74
|
+
);
|
|
75
|
+
while (packet.offset < extendedMetadataEnd) {
|
|
76
|
+
const id = packet.readInt8();
|
|
77
|
+
const value = packet.readLengthCodedString('ascii');
|
|
78
|
+
if (id === 0) {
|
|
79
|
+
this.extendedTypeName = value; // e.g. 'uuid', 'inet4', 'inet6', 'point'
|
|
80
|
+
} else if (id === 1) {
|
|
81
|
+
this.extendedFormat = value; // e.g. 'json'
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// a malformed entry could read past the block; resynchronise so the
|
|
85
|
+
// fixed column definition fields that follow parse from the right offset
|
|
86
|
+
packet.offset = extendedMetadataEnd;
|
|
87
|
+
}
|
|
88
|
+
|
|
60
89
|
inspect() {
|
|
61
90
|
return {
|
|
62
91
|
catalog: this.catalog,
|
|
@@ -288,4 +317,9 @@ addString('table');
|
|
|
288
317
|
addString('orgTable');
|
|
289
318
|
addString('orgName');
|
|
290
319
|
|
|
320
|
+
// MariaDB extended metadata defaults; instances only carry own values when
|
|
321
|
+
// the server actually tagged the column
|
|
322
|
+
ColumnDefinition.prototype.extendedTypeName = undefined;
|
|
323
|
+
ColumnDefinition.prototype.extendedFormat = undefined;
|
|
324
|
+
|
|
291
325
|
module.exports = ColumnDefinition;
|
|
@@ -11,7 +11,7 @@ function isJSON(value) {
|
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
function toParameter(value, encoding, timezone) {
|
|
14
|
+
function toParameter(value, encoding, timezone, jsonAsString) {
|
|
15
15
|
let type = Types.VAR_STRING;
|
|
16
16
|
let length;
|
|
17
17
|
let writer = function (value) {
|
|
@@ -46,8 +46,18 @@ function toParameter(value, encoding, timezone) {
|
|
|
46
46
|
};
|
|
47
47
|
} else if (isJSON(value)) {
|
|
48
48
|
value = JSON.stringify(value);
|
|
49
|
-
type
|
|
49
|
+
// MariaDB rejects the JSON parameter type with "Incorrect
|
|
50
|
+
// arguments to mysqld_stmt_execute"; it expects JSON values
|
|
51
|
+
// as plain strings
|
|
52
|
+
if (!jsonAsString) {
|
|
53
|
+
type = Types.JSON;
|
|
54
|
+
}
|
|
50
55
|
} else if (Buffer.isBuffer(value)) {
|
|
56
|
+
// send buffers as BLOB so servers treat the value as binary data
|
|
57
|
+
// rather than a string in the connection charset (MariaDB converts
|
|
58
|
+
// string parameters when storing into binary columns such as
|
|
59
|
+
// VECTOR, corrupting the value)
|
|
60
|
+
type = Types.BLOB;
|
|
51
61
|
length = Packet.lengthCodedNumberLength(value.length) + value.length;
|
|
52
62
|
writer = Packet.prototype.writeLengthCodedBuffer;
|
|
53
63
|
}
|
package/lib/packets/execute.js
CHANGED
|
@@ -15,7 +15,8 @@ class Execute {
|
|
|
15
15
|
charsetNumber,
|
|
16
16
|
timezone,
|
|
17
17
|
attributes,
|
|
18
|
-
clientFlags
|
|
18
|
+
clientFlags,
|
|
19
|
+
jsonAsString
|
|
19
20
|
) {
|
|
20
21
|
this.id = id;
|
|
21
22
|
this.parameters = parameters;
|
|
@@ -23,6 +24,7 @@ class Execute {
|
|
|
23
24
|
this.timezone = timezone;
|
|
24
25
|
this.attributes = attributes;
|
|
25
26
|
this.clientFlags = clientFlags || 0;
|
|
27
|
+
this.jsonAsString = jsonAsString || false;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
static fromPacket(packet, encoding) {
|
|
@@ -34,6 +36,7 @@ class Execute {
|
|
|
34
36
|
while (i < packet.end - 1) {
|
|
35
37
|
if (
|
|
36
38
|
(packet.buffer[i + 1] === Types.VAR_STRING ||
|
|
39
|
+
packet.buffer[i + 1] === Types.BLOB ||
|
|
37
40
|
packet.buffer[i + 1] === Types.NULL ||
|
|
38
41
|
packet.buffer[i + 1] === Types.DOUBLE ||
|
|
39
42
|
packet.buffer[i + 1] === Types.TINY ||
|
|
@@ -54,6 +57,7 @@ class Execute {
|
|
|
54
57
|
for (let i = packet.offset + 1; i < packet.end - 1; i++) {
|
|
55
58
|
if (
|
|
56
59
|
(packet.buffer[i] === Types.VAR_STRING ||
|
|
60
|
+
packet.buffer[i] === Types.BLOB ||
|
|
57
61
|
packet.buffer[i] === Types.NULL ||
|
|
58
62
|
packet.buffer[i] === Types.DOUBLE ||
|
|
59
63
|
packet.buffer[i] === Types.TINY ||
|
|
@@ -72,6 +76,8 @@ class Execute {
|
|
|
72
76
|
for (let i = 0; i < types.length; i++) {
|
|
73
77
|
if (types[i] === Types.VAR_STRING) {
|
|
74
78
|
values.push(packet.readLengthCodedString(encoding));
|
|
79
|
+
} else if (types[i] === Types.BLOB) {
|
|
80
|
+
values.push(packet.readLengthCodedBuffer());
|
|
75
81
|
} else if (types[i] === Types.DOUBLE) {
|
|
76
82
|
values.push(packet.readDouble());
|
|
77
83
|
} else if (types[i] === Types.TINY) {
|
|
@@ -119,7 +125,7 @@ class Execute {
|
|
|
119
125
|
const bindParams =
|
|
120
126
|
numParams > 0
|
|
121
127
|
? this.parameters.map((v) =>
|
|
122
|
-
toParameter(v, this.encoding, this.timezone)
|
|
128
|
+
toParameter(v, this.encoding, this.timezone, this.jsonAsString)
|
|
123
129
|
)
|
|
124
130
|
: [];
|
|
125
131
|
const attrParams = attrNames.map((name) =>
|
package/lib/packets/handshake.js
CHANGED
|
@@ -16,6 +16,7 @@ class Handshake {
|
|
|
16
16
|
this.characterSet = args.characterSet;
|
|
17
17
|
this.statusFlags = args.statusFlags;
|
|
18
18
|
this.authPluginName = args.authPluginName;
|
|
19
|
+
this.mariadbExtendedCapabilityFlags = args.mariadbExtendedCapabilityFlags;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
setScrambleData(cb) {
|
|
@@ -79,9 +80,20 @@ class Handshake {
|
|
|
79
80
|
args.authPluginDataLength = 0;
|
|
80
81
|
packet.skip(1);
|
|
81
82
|
}
|
|
82
|
-
packet.skip(
|
|
83
|
+
packet.skip(6);
|
|
84
|
+
if (args.capabilityFlags & ClientConstants.LONG_PASSWORD) {
|
|
85
|
+
// CLIENT_MYSQL (LONG_PASSWORD) set: a MySQL server, the remaining
|
|
86
|
+
// 4 reserved bytes are filler
|
|
87
|
+
packet.skip(4);
|
|
88
|
+
args.mariadbExtendedCapabilityFlags = 0;
|
|
89
|
+
} else {
|
|
90
|
+
// MariaDB servers (10.2+) leave CLIENT_MYSQL unset and use these
|
|
91
|
+
// 4 bytes to advertise MariaDB-specific capabilities
|
|
92
|
+
args.mariadbExtendedCapabilityFlags = packet.readInt32();
|
|
93
|
+
}
|
|
83
94
|
} else {
|
|
84
95
|
args.capabilityFlags = capabilityFlagsBuffer.readUInt16LE(0);
|
|
96
|
+
args.mariadbExtendedCapabilityFlags = 0;
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
const isSecureConnection =
|
|
@@ -16,6 +16,7 @@ class HandshakeResponse {
|
|
|
16
16
|
this.authPluginData2 = handshake.authPluginData2;
|
|
17
17
|
this.compress = handshake.compress;
|
|
18
18
|
this.clientFlags = handshake.flags;
|
|
19
|
+
this.mariadbExtendedClientFlags = handshake.mariadbExtendedClientFlags || 0;
|
|
19
20
|
|
|
20
21
|
// Accept pre-calculated authToken and authPluginName from caller
|
|
21
22
|
// This allows the caller to optimize by using the server's preferred auth method
|
|
@@ -69,7 +70,10 @@ class HandshakeResponse {
|
|
|
69
70
|
packet.writeInt32(this.clientFlags);
|
|
70
71
|
packet.writeInt32(0); // max packet size. todo: move to config
|
|
71
72
|
packet.writeInt8(this.charsetNumber);
|
|
72
|
-
|
|
73
|
+
// the last 4 of the 23 reserved bytes carry the MariaDB extended client
|
|
74
|
+
// capabilities (zero when not negotiated, i.e. plain filler)
|
|
75
|
+
packet.skip(19);
|
|
76
|
+
packet.writeInt32(this.mariadbExtendedClientFlags);
|
|
73
77
|
const encoding = this.encoding;
|
|
74
78
|
packet.writeNullTerminatedString(this.user, encoding);
|
|
75
79
|
let k;
|
package/lib/packets/packet.js
CHANGED
|
@@ -32,13 +32,40 @@ function leftPad(num, value) {
|
|
|
32
32
|
// In my benchmarks the difference is ~25M 8-digit numbers per second vs
|
|
33
33
|
// 4.5 M using Number(packet.readLengthCodedString())
|
|
34
34
|
// not used when size is close to max precision as series of *10 accumulate error
|
|
35
|
-
// and approximate result
|
|
36
|
-
// In the
|
|
35
|
+
// and approximate result might be different from (approximate as well) Number(bigNumStringValue))
|
|
36
|
+
// In the future node version if speed difference is smaller parse* functions might be removed
|
|
37
37
|
// don't consider them as Packet public API
|
|
38
38
|
|
|
39
39
|
const minus = '-'.charCodeAt(0);
|
|
40
40
|
const plus = '+'.charCodeAt(0);
|
|
41
41
|
|
|
42
|
+
// JSON.parse source access: proposal-json-parse-with-source,
|
|
43
|
+
// Node.js 22+ / V8 12.2
|
|
44
|
+
const jsonSourceAccessSupported = (() => {
|
|
45
|
+
let supported = false;
|
|
46
|
+
JSON.parse('0', (key, value, context) => {
|
|
47
|
+
supported = context !== undefined && typeof context.source === 'string';
|
|
48
|
+
return value;
|
|
49
|
+
});
|
|
50
|
+
return supported;
|
|
51
|
+
})();
|
|
52
|
+
|
|
53
|
+
// 16 digits is the shortest numeral that can exceed Number.MAX_SAFE_INTEGER
|
|
54
|
+
const jsonBigNumeral = /\d{16}/;
|
|
55
|
+
const jsonIntegerSource = /^-?\d+$/;
|
|
56
|
+
|
|
57
|
+
function jsonBigNumberReviver(key, value, context) {
|
|
58
|
+
if (
|
|
59
|
+
typeof value === 'number' &&
|
|
60
|
+
!Number.isSafeInteger(value) &&
|
|
61
|
+
context !== undefined &&
|
|
62
|
+
jsonIntegerSource.test(context.source)
|
|
63
|
+
) {
|
|
64
|
+
return context.source;
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
}
|
|
68
|
+
|
|
42
69
|
// TODO: handle E notation
|
|
43
70
|
const dot = '.'.charCodeAt(0);
|
|
44
71
|
const exponent = 'e'.charCodeAt(0);
|
|
@@ -290,6 +317,9 @@ class Packet {
|
|
|
290
317
|
return new Date(y, m - 1, d, H, M, S, ms);
|
|
291
318
|
}
|
|
292
319
|
let str = this.readDateTimeString(6, 'T', null);
|
|
320
|
+
if (!str) {
|
|
321
|
+
return INVALID_DATE;
|
|
322
|
+
}
|
|
293
323
|
if (str.length === 10) {
|
|
294
324
|
str += 'T00:00:00';
|
|
295
325
|
}
|
|
@@ -321,7 +351,10 @@ class Packet {
|
|
|
321
351
|
leftPad(2, M),
|
|
322
352
|
leftPad(2, S),
|
|
323
353
|
].join(':')}`;
|
|
324
|
-
} else if (
|
|
354
|
+
} else if (
|
|
355
|
+
columnType === Types.DATETIME ||
|
|
356
|
+
columnType === Types.TIMESTAMP
|
|
357
|
+
) {
|
|
325
358
|
str += ' 00:00:00';
|
|
326
359
|
}
|
|
327
360
|
if (length > 10) {
|
|
@@ -648,6 +681,21 @@ class Packet {
|
|
|
648
681
|
return result;
|
|
649
682
|
}
|
|
650
683
|
|
|
684
|
+
// With supportBigNumbers, unsafe integers become exact strings,
|
|
685
|
+
// mirroring the option's behaviour for BIGINT columns
|
|
686
|
+
parseJson(encoding, supportBigNumbers) {
|
|
687
|
+
const str = this.readLengthCodedString(encoding);
|
|
688
|
+
if (
|
|
689
|
+
supportBigNumbers &&
|
|
690
|
+
jsonSourceAccessSupported &&
|
|
691
|
+
str !== null &&
|
|
692
|
+
jsonBigNumeral.test(str)
|
|
693
|
+
) {
|
|
694
|
+
return JSON.parse(str, jsonBigNumberReviver);
|
|
695
|
+
}
|
|
696
|
+
return JSON.parse(str);
|
|
697
|
+
}
|
|
698
|
+
|
|
651
699
|
parseDate(timezone) {
|
|
652
700
|
const strLen = this.readLengthCodedNumber();
|
|
653
701
|
if (strLen === null) {
|
|
@@ -65,7 +65,7 @@ class ResultSetHeader {
|
|
|
65
65
|
if (key === 'character_set_client') {
|
|
66
66
|
const charsetNumber = EncodingToCharset[val];
|
|
67
67
|
// TODO - better api for driver users to handle unknown encodings?
|
|
68
|
-
// maybe custom
|
|
68
|
+
// maybe custom converter in the config?
|
|
69
69
|
// For now just ignore character_set_client command if there is
|
|
70
70
|
// no known mapping from reported encoding to a charset code
|
|
71
71
|
if (typeof charsetNumber !== 'undefined') {
|