mysql2 3.23.0 → 3.23.1-canary.01f1092
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.
|
@@ -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;
|
|
@@ -96,7 +96,7 @@ function compile(fields, options, config) {
|
|
|
96
96
|
const parserFn = genFunc();
|
|
97
97
|
const nullBitmapLength = Math.floor((fields.length + 7 + 2) / 8);
|
|
98
98
|
|
|
99
|
-
function
|
|
99
|
+
function fieldMetadata(field) {
|
|
100
100
|
return {
|
|
101
101
|
type: typeNames[field.columnType],
|
|
102
102
|
extendedTypeName: field.extendedTypeName,
|
|
@@ -105,6 +105,12 @@ function compile(fields, options, config) {
|
|
|
105
105
|
db: field.schema,
|
|
106
106
|
table: field.table,
|
|
107
107
|
name: field.name,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function wrap(field, packet) {
|
|
112
|
+
return {
|
|
113
|
+
...fieldMetadata(field),
|
|
108
114
|
string: function (encoding = field.encoding) {
|
|
109
115
|
if (field.columnType === Types.JSON && encoding === field.encoding) {
|
|
110
116
|
// Since for JSON columns mysql always returns charset 63 (BINARY),
|
|
@@ -148,6 +154,22 @@ function compile(fields, options, config) {
|
|
|
148
154
|
};
|
|
149
155
|
}
|
|
150
156
|
|
|
157
|
+
/** A NULL value carries no bytes in the binary row packet, so the accessors return null without reading from it. */
|
|
158
|
+
function wrapNull(field) {
|
|
159
|
+
return {
|
|
160
|
+
...fieldMetadata(field),
|
|
161
|
+
string: function () {
|
|
162
|
+
return null;
|
|
163
|
+
},
|
|
164
|
+
buffer: function () {
|
|
165
|
+
return null;
|
|
166
|
+
},
|
|
167
|
+
geometry: function () {
|
|
168
|
+
return null;
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
151
173
|
parserFn('(function(){');
|
|
152
174
|
parserFn('return class BinaryRow {');
|
|
153
175
|
parserFn('constructor() {');
|
|
@@ -196,9 +218,17 @@ function compile(fields, options, config) {
|
|
|
196
218
|
lvalue = `result[${fieldName}]`;
|
|
197
219
|
}
|
|
198
220
|
|
|
199
|
-
parserFn(`if (nullBitmaskByte${nullByteIndex} & ${currentFieldNullBit}) `);
|
|
200
|
-
|
|
201
|
-
|
|
221
|
+
parserFn(`if (nullBitmaskByte${nullByteIndex} & ${currentFieldNullBit}) {`);
|
|
222
|
+
if (typeof options.typeCast === 'function') {
|
|
223
|
+
const nullWrapperVar = `nullWrapper${i}`;
|
|
224
|
+
parserFn(`const ${nullWrapperVar} = wrapNull(fields[${i}]);`);
|
|
225
|
+
parserFn(
|
|
226
|
+
`${lvalue} = options.typeCast(${nullWrapperVar}, function() { return null; });`
|
|
227
|
+
);
|
|
228
|
+
} else {
|
|
229
|
+
parserFn(`${lvalue} = null;`);
|
|
230
|
+
}
|
|
231
|
+
parserFn('} else {');
|
|
202
232
|
|
|
203
233
|
if (options.typeCast === false) {
|
|
204
234
|
parserFn(`${lvalue} = packet.readLengthCodedBuffer();`);
|
|
@@ -234,7 +264,7 @@ function compile(fields, options, config) {
|
|
|
234
264
|
parserFn.toString()
|
|
235
265
|
);
|
|
236
266
|
}
|
|
237
|
-
return parserFn.toFunction({ wrap });
|
|
267
|
+
return parserFn.toFunction({ wrap, wrapNull });
|
|
238
268
|
}
|
|
239
269
|
|
|
240
270
|
function getBinaryParser(fields, options, config) {
|
|
@@ -94,6 +94,28 @@ function getBinaryParser(fields, _options, config) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
/** A NULL value carries no bytes in the binary row packet, so the accessors return null without reading from it. */
|
|
98
|
+
function wrapNull(field) {
|
|
99
|
+
return {
|
|
100
|
+
type: typeNames[field.columnType],
|
|
101
|
+
extendedTypeName: field.extendedTypeName,
|
|
102
|
+
extendedFormat: field.extendedFormat,
|
|
103
|
+
length: field.columnLength,
|
|
104
|
+
db: field.schema,
|
|
105
|
+
table: field.table,
|
|
106
|
+
name: field.name,
|
|
107
|
+
string: function () {
|
|
108
|
+
return null;
|
|
109
|
+
},
|
|
110
|
+
buffer: function () {
|
|
111
|
+
return null;
|
|
112
|
+
},
|
|
113
|
+
geometry: function () {
|
|
114
|
+
return null;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
97
119
|
return class BinaryRow {
|
|
98
120
|
constructor() {}
|
|
99
121
|
|
|
@@ -118,7 +140,10 @@ function getBinaryParser(fields, _options, config) {
|
|
|
118
140
|
|
|
119
141
|
let value;
|
|
120
142
|
if (nullBitmaskBytes[nullByteIndex] & currentFieldNullBit) {
|
|
121
|
-
value =
|
|
143
|
+
value =
|
|
144
|
+
typeof typeCast === 'function'
|
|
145
|
+
? typeCast(wrapNull(field), () => null)
|
|
146
|
+
: null;
|
|
122
147
|
} else if (options.typeCast === false) {
|
|
123
148
|
value = packet.readLengthCodedBuffer();
|
|
124
149
|
} else {
|
package/package.json
CHANGED