mysql2 3.24.6 → 3.24.7-canary.25c88d2
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/index.js +1 -0
- package/lib/commands/change_user.js +2 -1
- package/lib/commands/client_handshake.js +25 -0
- package/lib/commands/execute.js +20 -4
- package/lib/packets/encode_parameter.js +4 -2
- package/lib/packets/packet.js +27 -7
- package/lib/packets/typed_parameter.js +11 -2
- package/lib/parsers/binary_parser.js +35 -22
- package/lib/parsers/static_binary_parser.js +11 -4
- package/lib/parsers/static_text_parser.js +5 -2
- package/lib/parsers/text_parser.js +5 -2
- package/lib/pool_cluster.js +1 -1
- package/package.json +10 -9
- package/promise.js +1 -0
- package/typings/mysql/index.d.ts +3 -1
- package/typings/mysql/lib/Connection.d.ts +3 -3
- package/typings/mysql/lib/TypedParameter.d.ts +1 -1
- package/typings/mysql/lib/protocol/sequences/Query.d.ts +6 -6
package/index.js
CHANGED
|
@@ -30,7 +30,8 @@ class ChangeUser extends Command {
|
|
|
30
30
|
}
|
|
31
31
|
start(packet, connection) {
|
|
32
32
|
const newPacket = new Packets.ChangeUser({
|
|
33
|
-
flags:
|
|
33
|
+
flags:
|
|
34
|
+
connection.config.clientFlags & (connection.serverCapabilityFlags || 0),
|
|
34
35
|
user: this.user,
|
|
35
36
|
database: this.database,
|
|
36
37
|
charsetNumber: this.charsetNumber,
|
|
@@ -31,6 +31,17 @@ function flagNames(flags) {
|
|
|
31
31
|
return res;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
const SERVER_REQUEST_FLAGS =
|
|
35
|
+
ClientConstants.FOUND_ROWS |
|
|
36
|
+
ClientConstants.IGNORE_SPACE |
|
|
37
|
+
ClientConstants.INTERACTIVE |
|
|
38
|
+
ClientConstants.LOCAL_FILES |
|
|
39
|
+
ClientConstants.MULTI_STATEMENTS |
|
|
40
|
+
ClientConstants.MULTI_RESULTS |
|
|
41
|
+
ClientConstants.PS_MULTI_RESULTS;
|
|
42
|
+
|
|
43
|
+
const ALWAYS_SENT_FLAGS = ClientConstants.PROTOCOL_41 | SERVER_REQUEST_FLAGS;
|
|
44
|
+
|
|
34
45
|
class ClientHandshake extends Command {
|
|
35
46
|
constructor(clientFlags) {
|
|
36
47
|
super();
|
|
@@ -44,6 +55,19 @@ class ClientHandshake extends Command {
|
|
|
44
55
|
return ClientHandshake.prototype.handshakeInit;
|
|
45
56
|
}
|
|
46
57
|
|
|
58
|
+
dropUnsupportedClientFlags(connection) {
|
|
59
|
+
const supportedFlags = this.handshake.capabilityFlags | ALWAYS_SENT_FLAGS;
|
|
60
|
+
const droppedFlags = this.clientFlags & ~supportedFlags;
|
|
61
|
+
if (connection.config.debug && droppedFlags) {
|
|
62
|
+
console.log(
|
|
63
|
+
'Dropping client flags the server does not support: flags:%d=(%s)',
|
|
64
|
+
droppedFlags,
|
|
65
|
+
flagNames(droppedFlags).join(', ')
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
this.clientFlags &= supportedFlags;
|
|
69
|
+
}
|
|
70
|
+
|
|
47
71
|
sendSSLRequest(connection) {
|
|
48
72
|
const sslRequest = new Packets.SSLRequest(
|
|
49
73
|
this.clientFlags,
|
|
@@ -267,6 +291,7 @@ class ClientHandshake extends Command {
|
|
|
267
291
|
);
|
|
268
292
|
}
|
|
269
293
|
connection.serverCapabilityFlags = this.handshake.capabilityFlags;
|
|
294
|
+
this.dropUnsupportedClientFlags(connection);
|
|
270
295
|
connection.serverEncoding = CharsetToEncoding[this.handshake.characterSet];
|
|
271
296
|
connection.connectionId = this.handshake.connectionId;
|
|
272
297
|
// MariaDB needs a few protocol deviations, e.g. it rejects the JSON
|
package/lib/commands/execute.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const Timers = require('timers');
|
|
4
|
+
const SqlString = require('sql-escaper');
|
|
4
5
|
|
|
5
6
|
const Command = require('./command.js');
|
|
6
7
|
const Query = require('./query.js');
|
|
@@ -10,9 +11,24 @@ const ConnectionConfig = require('../connection_config.js');
|
|
|
10
11
|
const getBinaryParser = require('../parsers/binary_parser.js');
|
|
11
12
|
const getStaticBinaryParser = require('../parsers/static_binary_parser.js');
|
|
12
13
|
|
|
14
|
+
const isExpandMark = (value) =>
|
|
15
|
+
typeof value === 'object' &&
|
|
16
|
+
value !== null &&
|
|
17
|
+
Object.prototype.hasOwnProperty.call(value, SqlString.EXPAND_SYMBOL);
|
|
18
|
+
|
|
13
19
|
class Execute extends Command {
|
|
14
20
|
constructor(options, callback) {
|
|
15
21
|
super();
|
|
22
|
+
if (options.values) {
|
|
23
|
+
for (let index = 0; index < options.values.length; index++) {
|
|
24
|
+
if (isExpandMark(options.values[index])) {
|
|
25
|
+
throw new TypeError(
|
|
26
|
+
'Bind parameters must not contain expand() marks. Use query() instead'
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
16
32
|
this.statement = options.statement;
|
|
17
33
|
this.sql = options.sql;
|
|
18
34
|
this.values = options.values;
|
|
@@ -114,10 +130,10 @@ class Execute extends Command {
|
|
|
114
130
|
if (!packet.isEOF()) {
|
|
115
131
|
return connection.protocolError('Expected EOF packet');
|
|
116
132
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
133
|
+
const fields = this._fields[this._resultIndex];
|
|
134
|
+
this._rowParser = new (this.buildParserFromFields(fields, connection))(
|
|
135
|
+
fields
|
|
136
|
+
);
|
|
121
137
|
return Execute.prototype.row;
|
|
122
138
|
}
|
|
123
139
|
}
|
|
@@ -5,6 +5,7 @@ const Packet = require('../packets/packet');
|
|
|
5
5
|
const StringParser = require('../parsers/string.js');
|
|
6
6
|
const {
|
|
7
7
|
TypedParameter,
|
|
8
|
+
asBuffer,
|
|
8
9
|
encodeTypedParameter,
|
|
9
10
|
integerHint,
|
|
10
11
|
} = require('./typed_parameter.js');
|
|
@@ -68,11 +69,12 @@ function toParameter(value, encoding, timezone, jsonAsString, hint) {
|
|
|
68
69
|
if (!jsonAsString) {
|
|
69
70
|
type = Types.JSON;
|
|
70
71
|
}
|
|
71
|
-
} else if (
|
|
72
|
+
} else if (ArrayBuffer.isView(value)) {
|
|
72
73
|
// send buffers as BLOB so servers treat the value as binary data
|
|
73
74
|
// rather than a string in the connection charset (MariaDB converts
|
|
74
75
|
// string parameters when storing into binary columns such as
|
|
75
76
|
// VECTOR, corrupting the value)
|
|
77
|
+
value = asBuffer(value);
|
|
76
78
|
type = Types.BLOB;
|
|
77
79
|
length = Packet.lengthCodedNumberLength(value.length) + value.length;
|
|
78
80
|
writer = Packet.prototype.writeLengthCodedBuffer;
|
|
@@ -90,7 +92,7 @@ function toParameter(value, encoding, timezone, jsonAsString, hint) {
|
|
|
90
92
|
}
|
|
91
93
|
let byteLength;
|
|
92
94
|
if (length === undefined) {
|
|
93
|
-
// a non-string here
|
|
95
|
+
// a non-string here keeps the Buffer.from coercion
|
|
94
96
|
// inside StringParser.encode
|
|
95
97
|
if (
|
|
96
98
|
typeof value === 'string' &&
|
package/lib/packets/packet.js
CHANGED
|
@@ -186,15 +186,21 @@ class Packet {
|
|
|
186
186
|
readInt64String() {
|
|
187
187
|
const word0 = this.readInt32();
|
|
188
188
|
const word1 = this.readInt32();
|
|
189
|
-
const
|
|
190
|
-
|
|
189
|
+
const resNumber = word0 + 0x100000000 * word1;
|
|
190
|
+
if (Number.isSafeInteger(resNumber)) {
|
|
191
|
+
return String(resNumber);
|
|
192
|
+
}
|
|
193
|
+
return new Long(word0, word1, true).toString();
|
|
191
194
|
}
|
|
192
195
|
|
|
193
196
|
readSInt64String() {
|
|
194
197
|
const word0 = this.readInt32();
|
|
195
198
|
const word1 = this.readInt32();
|
|
196
|
-
const
|
|
197
|
-
|
|
199
|
+
const resNumber = word0 + 0x100000000 * (word1 | 0);
|
|
200
|
+
if (Number.isSafeInteger(resNumber)) {
|
|
201
|
+
return String(resNumber);
|
|
202
|
+
}
|
|
203
|
+
return new Long(word0, word1, false).toString();
|
|
198
204
|
}
|
|
199
205
|
|
|
200
206
|
readInt64() {
|
|
@@ -391,15 +397,23 @@ class Packet {
|
|
|
391
397
|
}
|
|
392
398
|
}
|
|
393
399
|
str += ms;
|
|
400
|
+
} else if (
|
|
401
|
+
decimals > 0 &&
|
|
402
|
+
decimals <= 6 &&
|
|
403
|
+
(columnType === Types.DATETIME || columnType === Types.TIMESTAMP)
|
|
404
|
+
) {
|
|
405
|
+
str += `.${'0'.repeat(decimals)}`;
|
|
394
406
|
}
|
|
395
407
|
return str;
|
|
396
408
|
}
|
|
397
409
|
|
|
398
410
|
// TIME - value as a string, Can be negative
|
|
399
|
-
readTimeString(convertTtoMs) {
|
|
411
|
+
readTimeString(convertTtoMs, decimals) {
|
|
400
412
|
const length = this.readInt8();
|
|
401
413
|
if (length === 0) {
|
|
402
|
-
return
|
|
414
|
+
return decimals > 0 && decimals <= 6
|
|
415
|
+
? `00:00:00.${'0'.repeat(decimals)}`
|
|
416
|
+
: '00:00:00';
|
|
403
417
|
}
|
|
404
418
|
const sign = this.readInt8() ? -1 : 1; // 'isNegative' flag byte
|
|
405
419
|
let d = 0;
|
|
@@ -426,10 +440,16 @@ class Packet {
|
|
|
426
440
|
}
|
|
427
441
|
// Format follows mySQL TIME format ([-][h]hh:mm:ss[.u[u[u[u[u[u]]]]]])
|
|
428
442
|
// For positive times below 24 hours, this makes it equal to ISO 8601 times
|
|
443
|
+
let fraction = '';
|
|
444
|
+
if (decimals > 0 && decimals <= 6) {
|
|
445
|
+
fraction = `.${leftPad(6, ms).substring(0, decimals)}`;
|
|
446
|
+
} else if (ms) {
|
|
447
|
+
fraction = `.${leftPad(6, ms)}`.replace(/0+$/, '');
|
|
448
|
+
}
|
|
429
449
|
return (
|
|
430
450
|
(sign === -1 ? '-' : '') +
|
|
431
451
|
[leftPad(2, d * 24 + H), leftPad(2, M), leftPad(2, S)].join(':') +
|
|
432
|
-
|
|
452
|
+
fraction
|
|
433
453
|
);
|
|
434
454
|
}
|
|
435
455
|
|
|
@@ -236,9 +236,17 @@ function timeEncoder() {
|
|
|
236
236
|
};
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
+
function asBuffer(bytes) {
|
|
240
|
+
return Buffer.isBuffer(bytes)
|
|
241
|
+
? bytes
|
|
242
|
+
: Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
243
|
+
}
|
|
244
|
+
|
|
239
245
|
function lengthCodedEncoder(encoding) {
|
|
240
246
|
return (value) => {
|
|
241
|
-
if (
|
|
247
|
+
if (ArrayBuffer.isView(value)) {
|
|
248
|
+
value = asBuffer(value);
|
|
249
|
+
} else {
|
|
242
250
|
const string = typeof value === 'string' ? value : String(value);
|
|
243
251
|
if (
|
|
244
252
|
StringParser.hasFastUtf8Write &&
|
|
@@ -266,7 +274,7 @@ function jsonEncoder(encoding) {
|
|
|
266
274
|
const encodeText = lengthCodedEncoder(encoding);
|
|
267
275
|
return (value) =>
|
|
268
276
|
encodeText(
|
|
269
|
-
typeof value === 'string' ||
|
|
277
|
+
typeof value === 'string' || ArrayBuffer.isView(value)
|
|
270
278
|
? value
|
|
271
279
|
: JSON.stringify(value)
|
|
272
280
|
);
|
|
@@ -385,6 +393,7 @@ for (const [alias, target] of Object.entries(ALIASES)) {
|
|
|
385
393
|
|
|
386
394
|
module.exports = {
|
|
387
395
|
TypedParameter,
|
|
396
|
+
asBuffer,
|
|
388
397
|
encodeTypedParameter,
|
|
389
398
|
integerHint,
|
|
390
399
|
types,
|
|
@@ -25,9 +25,15 @@ function readCodeFor(field, config, options, fieldNum) {
|
|
|
25
25
|
// MariaDB sends JSON values as LONGTEXT; the JSON type is only visible in
|
|
26
26
|
// the extended metadata (MARIADB_CLIENT_EXTENDED_METADATA capability)
|
|
27
27
|
if (field.extendedFormat === 'json') {
|
|
28
|
+
// a binary column holds the JSON text as bytes, which the JSON specs
|
|
29
|
+
// define as "utf8", as for the JSON type below
|
|
30
|
+
const jsonEncoding =
|
|
31
|
+
field.characterSet === Charsets.BINARY
|
|
32
|
+
? '"utf8"'
|
|
33
|
+
: `fields[${fieldNum}].encoding`;
|
|
28
34
|
return config.jsonStrings
|
|
29
|
-
? `packet.readLengthCodedString(
|
|
30
|
-
: `packet.parseJson(
|
|
35
|
+
? `packet.readLengthCodedString(${jsonEncoding})`
|
|
36
|
+
: `packet.parseJson(${jsonEncoding}, ${supportBigNumbers});`;
|
|
31
37
|
}
|
|
32
38
|
switch (field.columnType) {
|
|
33
39
|
case Types.TINY:
|
|
@@ -54,7 +60,7 @@ function readCodeFor(field, config, options, fieldNum) {
|
|
|
54
60
|
}
|
|
55
61
|
return `packet.readDateTime(${helpers.srcEscape(timezone)});`;
|
|
56
62
|
case Types.TIME:
|
|
57
|
-
return
|
|
63
|
+
return `packet.readTimeString(false, ${parseInt(field.decimals, 10)})`;
|
|
58
64
|
case Types.DECIMAL:
|
|
59
65
|
case Types.NEWDECIMAL:
|
|
60
66
|
if (config.decimalNumbers) {
|
|
@@ -109,10 +115,11 @@ function compile(fields, options, config) {
|
|
|
109
115
|
};
|
|
110
116
|
}
|
|
111
117
|
|
|
112
|
-
function wrap(field,
|
|
118
|
+
function wrap(field, row) {
|
|
113
119
|
return {
|
|
114
120
|
...fieldMetadata(field),
|
|
115
121
|
string: function (encoding = field.encoding) {
|
|
122
|
+
const packet = row.packet;
|
|
116
123
|
if (field.columnType === Types.JSON && encoding === field.encoding) {
|
|
117
124
|
// Since for JSON columns mysql always returns charset 63 (BINARY),
|
|
118
125
|
// we have to handle it according to JSON specs and use "utf8",
|
|
@@ -141,16 +148,16 @@ function compile(fields, options, config) {
|
|
|
141
148
|
}
|
|
142
149
|
|
|
143
150
|
if (field.columnType === Types.TIME) {
|
|
144
|
-
return packet.readTimeString();
|
|
151
|
+
return packet.readTimeString(false, parseInt(field.decimals, 10));
|
|
145
152
|
}
|
|
146
153
|
|
|
147
154
|
return packet.readLengthCodedString(encoding);
|
|
148
155
|
},
|
|
149
156
|
buffer: function () {
|
|
150
|
-
return packet.readLengthCodedBuffer();
|
|
157
|
+
return row.packet.readLengthCodedBuffer();
|
|
151
158
|
},
|
|
152
159
|
geometry: function () {
|
|
153
|
-
return packet.parseGeometryValue();
|
|
160
|
+
return row.packet.parseGeometryValue();
|
|
154
161
|
},
|
|
155
162
|
};
|
|
156
163
|
}
|
|
@@ -171,29 +178,39 @@ function compile(fields, options, config) {
|
|
|
171
178
|
};
|
|
172
179
|
}
|
|
173
180
|
|
|
181
|
+
// Global typeCast
|
|
182
|
+
if (
|
|
183
|
+
typeof config.typeCast === 'function' &&
|
|
184
|
+
typeof options.typeCast !== 'function'
|
|
185
|
+
) {
|
|
186
|
+
options.typeCast = config.typeCast;
|
|
187
|
+
}
|
|
188
|
+
|
|
174
189
|
parserFn('(function(){');
|
|
175
190
|
parserFn('return class BinaryRow {');
|
|
176
|
-
parserFn('constructor() {');
|
|
191
|
+
parserFn('constructor(fields) {');
|
|
177
192
|
if (fields.some((field) => LocalDate.usesLocalDate(field, options, config))) {
|
|
178
193
|
parserFn('LocalDate.checkTimezone();');
|
|
179
194
|
}
|
|
195
|
+
if (typeof options.typeCast === 'function') {
|
|
196
|
+
parserFn('this.packet = null;');
|
|
197
|
+
for (let i = 0; i < fields.length; ++i) {
|
|
198
|
+
parserFn(`this.wrap${i} = wrap(fields[${i}], this);`);
|
|
199
|
+
parserFn(`this.nullWrap${i} = wrapNull(fields[${i}]);`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
180
202
|
parserFn('}');
|
|
181
203
|
|
|
182
204
|
parserFn('next(packet, fields, options) {');
|
|
205
|
+
if (typeof options.typeCast === 'function') {
|
|
206
|
+
parserFn('this.packet = packet;');
|
|
207
|
+
}
|
|
183
208
|
if (options.rowsAsArray) {
|
|
184
209
|
parserFn(`const result = new Array(${fields.length});`);
|
|
185
210
|
} else {
|
|
186
211
|
parserFn('const result = {};');
|
|
187
212
|
}
|
|
188
213
|
|
|
189
|
-
// Global typeCast
|
|
190
|
-
if (
|
|
191
|
-
typeof config.typeCast === 'function' &&
|
|
192
|
-
typeof options.typeCast !== 'function'
|
|
193
|
-
) {
|
|
194
|
-
options.typeCast = config.typeCast;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
214
|
parserFn('packet.readInt8();'); // status byte
|
|
198
215
|
for (let i = 0; i < nullBitmapLength; ++i) {
|
|
199
216
|
parserFn(`const nullBitmaskByte${i} = packet.readInt8();`);
|
|
@@ -224,10 +241,8 @@ function compile(fields, options, config) {
|
|
|
224
241
|
|
|
225
242
|
parserFn(`if (nullBitmaskByte${nullByteIndex} & ${currentFieldNullBit}) {`);
|
|
226
243
|
if (typeof options.typeCast === 'function') {
|
|
227
|
-
const nullWrapperVar = `nullWrapper${i}`;
|
|
228
|
-
parserFn(`const ${nullWrapperVar} = wrapNull(fields[${i}]);`);
|
|
229
244
|
parserFn(
|
|
230
|
-
`${lvalue} = options.typeCast(${
|
|
245
|
+
`${lvalue} = options.typeCast(this.nullWrap${i}, function() { return null; });`
|
|
231
246
|
);
|
|
232
247
|
} else {
|
|
233
248
|
parserFn(`${lvalue} = null;`);
|
|
@@ -240,10 +255,8 @@ function compile(fields, options, config) {
|
|
|
240
255
|
const readCode = readCodeFor(fields[i], config, options, i);
|
|
241
256
|
|
|
242
257
|
if (typeof options.typeCast === 'function') {
|
|
243
|
-
const fieldWrapperVar = `fieldWrapper${i}`;
|
|
244
|
-
parserFn(`const ${fieldWrapperVar} = wrap(fields[${i}], packet);`);
|
|
245
258
|
parserFn(
|
|
246
|
-
`${lvalue} = options.typeCast(${
|
|
259
|
+
`${lvalue} = options.typeCast(this.wrap${i}, function() { return ${readCode} });`
|
|
247
260
|
);
|
|
248
261
|
} else {
|
|
249
262
|
parserFn(`${lvalue} = ${readCode};`);
|
|
@@ -31,9 +31,13 @@ function getBinaryParser(fields, queryOptions, config) {
|
|
|
31
31
|
// MariaDB sends JSON values as LONGTEXT; the JSON type is only visible in
|
|
32
32
|
// the extended metadata (MARIADB_CLIENT_EXTENDED_METADATA capability)
|
|
33
33
|
if (field.extendedFormat === 'json') {
|
|
34
|
+
// a binary column holds the JSON text as bytes, which the JSON specs
|
|
35
|
+
// define as "utf8", as for the JSON type below
|
|
36
|
+
const jsonEncoding =
|
|
37
|
+
field.characterSet === Charsets.BINARY ? 'utf8' : field.encoding;
|
|
34
38
|
return config.jsonStrings
|
|
35
|
-
? packet.readLengthCodedString(
|
|
36
|
-
: packet.parseJson(
|
|
39
|
+
? packet.readLengthCodedString(jsonEncoding)
|
|
40
|
+
: packet.parseJson(jsonEncoding, supportBigNumbers);
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
switch (field.columnType) {
|
|
@@ -64,7 +68,7 @@ function getBinaryParser(fields, queryOptions, config) {
|
|
|
64
68
|
)
|
|
65
69
|
: packet.readDateTime(timezone);
|
|
66
70
|
case Types.TIME:
|
|
67
|
-
return packet.readTimeString();
|
|
71
|
+
return packet.readTimeString(false, parseInt(field.decimals, 10));
|
|
68
72
|
case Types.DECIMAL:
|
|
69
73
|
case Types.NEWDECIMAL:
|
|
70
74
|
return config.decimalNumbers
|
|
@@ -202,7 +206,10 @@ function getBinaryParser(fields, queryOptions, config) {
|
|
|
202
206
|
}
|
|
203
207
|
|
|
204
208
|
if (field.columnType === Types.TIME) {
|
|
205
|
-
return packet.readTimeString(
|
|
209
|
+
return packet.readTimeString(
|
|
210
|
+
false,
|
|
211
|
+
parseInt(field.decimals, 10)
|
|
212
|
+
);
|
|
206
213
|
}
|
|
207
214
|
|
|
208
215
|
return packet.readLengthCodedString(encoding);
|
|
@@ -31,9 +31,12 @@ function readField({
|
|
|
31
31
|
// MariaDB sends JSON values as LONGTEXT; the JSON type is only visible in
|
|
32
32
|
// the extended metadata (MARIADB_CLIENT_EXTENDED_METADATA capability)
|
|
33
33
|
if (field.extendedFormat === 'json') {
|
|
34
|
+
// a binary column holds the JSON text as bytes, which the JSON specs
|
|
35
|
+
// define as "utf8", as for the JSON type below
|
|
36
|
+
const jsonEncoding = charset === Charsets.BINARY ? 'utf8' : encoding;
|
|
34
37
|
return config.jsonStrings
|
|
35
|
-
? packet.readLengthCodedString(
|
|
36
|
-
: packet.parseJson(
|
|
38
|
+
? packet.readLengthCodedString(jsonEncoding)
|
|
39
|
+
: packet.parseJson(jsonEncoding, supportBigNumbers);
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
switch (type) {
|
|
@@ -27,9 +27,12 @@ function readCodeFor(field, encodingExpr, config, options) {
|
|
|
27
27
|
// MariaDB sends JSON values as LONGTEXT; the JSON type is only visible in
|
|
28
28
|
// the extended metadata (MARIADB_CLIENT_EXTENDED_METADATA capability)
|
|
29
29
|
if (field.extendedFormat === 'json') {
|
|
30
|
+
// a binary column holds the JSON text as bytes, which the JSON specs
|
|
31
|
+
// define as "utf8", as for the JSON type below
|
|
32
|
+
const jsonEncoding = charset === Charsets.BINARY ? '"utf8"' : encodingExpr;
|
|
30
33
|
return config.jsonStrings
|
|
31
|
-
? `packet.readLengthCodedString(${
|
|
32
|
-
: `packet.parseJson(${
|
|
34
|
+
? `packet.readLengthCodedString(${jsonEncoding})`
|
|
35
|
+
: `packet.parseJson(${jsonEncoding}, ${supportBigNumbers})`;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
switch (type) {
|
package/lib/pool_cluster.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mysql2",
|
|
3
|
-
"version": "3.24.
|
|
3
|
+
"version": "3.24.7-canary.25c88d2",
|
|
4
4
|
"description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "typings/mysql/index",
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
"src:test:bun": "npm run src:build && tsx tools/src/prepare-tests.mts && bun poku --config=tools/src/poku.config.mts",
|
|
27
27
|
"src:test:deno": "npm run src:build && tsx tools/src/prepare-tests.mts && deno run -A npm:poku --config=tools/src/poku.config.mts",
|
|
28
28
|
"benchmark": "node ./benchmarks/benchmark.js",
|
|
29
|
-
"wait-port": "wait-on"
|
|
29
|
+
"wait-port": "wait-on",
|
|
30
|
+
"checkout": "bash scripts/checkout.sh"
|
|
30
31
|
},
|
|
31
32
|
"repository": {
|
|
32
33
|
"type": "git",
|
|
@@ -62,30 +63,30 @@
|
|
|
62
63
|
"generate-function": "^2.3.1",
|
|
63
64
|
"iconv-lite": "^0.7.3",
|
|
64
65
|
"long": "^5.3.2",
|
|
65
|
-
"lru.min": "^1.1.
|
|
66
|
+
"lru.min": "^1.1.5",
|
|
66
67
|
"named-placeholders": "^1.1.6",
|
|
67
|
-
"sql-escaper": "^1.
|
|
68
|
+
"sql-escaper": "^1.7.0"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
71
|
"@types/node": ">= 8"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
|
-
"@biomejs/biome": "^2.
|
|
74
|
+
"@biomejs/biome": "^2.6.8",
|
|
74
75
|
"@ianvs/prettier-plugin-sort-imports": "^4.7.1",
|
|
75
76
|
"@pokujs/multi-suite": "^1.0.2",
|
|
76
77
|
"@rollup/plugin-commonjs": "^29.0.3",
|
|
77
78
|
"@rollup/plugin-json": "^6.1.0",
|
|
78
79
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
79
|
-
"@types/node": "^26.
|
|
80
|
+
"@types/node": "^26.6.6",
|
|
80
81
|
"assert-diff": "^3.0.4",
|
|
81
82
|
"benchmark": "^2.1.4",
|
|
82
83
|
"c8": "^12.0.0",
|
|
83
84
|
"error-stack-parser": "^2.1.4",
|
|
84
85
|
"poku": "^4.5.0",
|
|
85
86
|
"portfinder": "^1.0.38",
|
|
86
|
-
"prettier": "^3.
|
|
87
|
-
"rollup": "^4.
|
|
88
|
-
"tsx": "^4.23.
|
|
87
|
+
"prettier": "^3.10.1",
|
|
88
|
+
"rollup": "^4.68.4",
|
|
89
|
+
"tsx": "^4.23.15",
|
|
89
90
|
"typescript": "^7.0.2"
|
|
90
91
|
}
|
|
91
92
|
}
|
package/promise.js
CHANGED
|
@@ -184,6 +184,7 @@ exports.escape = SqlString.escape;
|
|
|
184
184
|
exports.escapeId = SqlString.escapeId;
|
|
185
185
|
exports.format = SqlString.format;
|
|
186
186
|
exports.raw = SqlString.raw;
|
|
187
|
+
exports.expand = SqlString.expand;
|
|
187
188
|
exports.Connection = PromiseConnection;
|
|
188
189
|
exports.PoolConnection = PromisePoolConnection;
|
|
189
190
|
exports.PromisePool = PromisePool;
|
package/typings/mysql/index.d.ts
CHANGED
|
@@ -26,8 +26,9 @@ import {
|
|
|
26
26
|
escapeId as SqlStringEscapeId,
|
|
27
27
|
format as SqlStringFormat,
|
|
28
28
|
raw as SqlStringRaw,
|
|
29
|
+
expand as SqlStringExpand,
|
|
29
30
|
} from 'sql-escaper';
|
|
30
|
-
export type { Raw, SqlValue, Timezone } from 'sql-escaper';
|
|
31
|
+
export type { Expand, Raw, SqlValue, Timezone } from 'sql-escaper';
|
|
31
32
|
|
|
32
33
|
export {
|
|
33
34
|
ConnectionOptions,
|
|
@@ -68,6 +69,7 @@ export const escape: typeof SqlStringEscape;
|
|
|
68
69
|
export const escapeId: typeof SqlStringEscapeId;
|
|
69
70
|
export const format: typeof SqlStringFormat;
|
|
70
71
|
export const raw: typeof SqlStringRaw;
|
|
72
|
+
export const expand: typeof SqlStringExpand;
|
|
71
73
|
|
|
72
74
|
export interface ConnectionConfig extends ConnectionOptions {
|
|
73
75
|
mergeFlags(defaultFlags: string[], userFlags: string[] | string): number;
|
|
@@ -122,9 +122,9 @@ export interface ConnectionOptions {
|
|
|
122
122
|
database?: string;
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
|
-
* The charset for the connection. This is called 'collation' in the SQL-level of MySQL (like
|
|
126
|
-
*
|
|
127
|
-
* (Default: '
|
|
125
|
+
* The charset for the connection. This is called 'collation' in the SQL-level of MySQL (like utf8mb4_unicode_ci).
|
|
126
|
+
* A charset name (like utf8mb4) uses a fixed collation (utf8mb4_general_ci), not the server's default.
|
|
127
|
+
* (Default: 'UTF8MB4_UNICODE_CI')
|
|
128
128
|
*/
|
|
129
129
|
charset?: string;
|
|
130
130
|
|
|
@@ -12,7 +12,7 @@ export interface TypedParameterValue {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export type TypedParameterInput =
|
|
15
|
-
string | number | bigint | boolean | Date | Buffer |
|
|
15
|
+
string | number | bigint | boolean | Date | Buffer | ArrayBufferView | null;
|
|
16
16
|
|
|
17
17
|
export interface TypedParameterFactory {
|
|
18
18
|
(value: TypedParameterInput): TypedParameterValue;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Sequence } from './Sequence.js';
|
|
2
2
|
import { OkPacket, RowDataPacket, FieldPacket } from '../packets/index.js';
|
|
3
3
|
import { Readable } from 'stream';
|
|
4
|
-
import { Raw, Timezone } from 'sql-escaper';
|
|
4
|
+
import { Expand, Raw, Timezone } from 'sql-escaper';
|
|
5
5
|
import { TypeCast } from '../../parsers/typeCast.js';
|
|
6
6
|
import { TypedParameterValue } from '../../TypedParameter.js';
|
|
7
7
|
|
|
@@ -15,7 +15,7 @@ export type ExecuteValues =
|
|
|
15
15
|
| null
|
|
16
16
|
| Blob
|
|
17
17
|
| Buffer
|
|
18
|
-
|
|
|
18
|
+
| ArrayBufferView
|
|
19
19
|
| ExecuteValues[]
|
|
20
20
|
| { [key: string]: ExecuteValues };
|
|
21
21
|
|
|
@@ -31,6 +31,7 @@ export type QueryValues =
|
|
|
31
31
|
| Buffer
|
|
32
32
|
| Uint8Array
|
|
33
33
|
| Raw
|
|
34
|
+
| Expand
|
|
34
35
|
| ({} | null | undefined)[]
|
|
35
36
|
| { [key: string]: QueryValues };
|
|
36
37
|
|
|
@@ -58,10 +59,9 @@ export interface QueryOptions {
|
|
|
58
59
|
namedPlaceholders?: boolean;
|
|
59
60
|
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* destroyed and no further operations can be performed.
|
|
62
|
+
* The maximum time, in milliseconds, that the query may take, counted from when it starts running until its whole
|
|
63
|
+
* result has been received. It is not reset when data arrives. With `stream()`, receiving pauses while the consumer
|
|
64
|
+
* falls behind, so that time counts too.
|
|
65
65
|
*/
|
|
66
66
|
timeout?: number;
|
|
67
67
|
|