mssql 12.7.2 → 12.7.3
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/lib/msnodesqlv8/request.js +26 -10
- package/lib/tedious/request.js +19 -6
- package/package.json +1 -1
|
@@ -302,7 +302,7 @@ class Request extends BaseRequest {
|
|
|
302
302
|
})
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
_query (command, callback) {
|
|
305
|
+
_query (command, callback, bound) {
|
|
306
306
|
super._query(command, err => {
|
|
307
307
|
if (err) return callback(err)
|
|
308
308
|
|
|
@@ -392,7 +392,9 @@ class Request extends BaseRequest {
|
|
|
392
392
|
continue
|
|
393
393
|
}
|
|
394
394
|
const param = this.parameters[name]
|
|
395
|
-
|
|
395
|
+
// an output's initial value is bound with the inputs below, so it needs a marker too;
|
|
396
|
+
// an output given no value is null, and 0, '' and false are values like any other
|
|
397
|
+
if (param.io === 1 || (param.io === 2 && param.value != null)) {
|
|
396
398
|
sets.push(`set @${param.name}=?`)
|
|
397
399
|
}
|
|
398
400
|
}
|
|
@@ -426,15 +428,23 @@ class Request extends BaseRequest {
|
|
|
426
428
|
return callback(new RequestError('Canceled.', 'ECANCEL'))
|
|
427
429
|
}
|
|
428
430
|
|
|
431
|
+
// values are bound to the markers by position, so a caller that writes its own
|
|
432
|
+
// markers passes the parameters in the order it wrote them
|
|
429
433
|
const params = []
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
continue
|
|
433
|
-
}
|
|
434
|
-
const param = this.parameters[name]
|
|
435
|
-
if (param.io === 1 || (param.io === 2 && param.value)) {
|
|
434
|
+
if (bound) {
|
|
435
|
+
for (const param of bound) {
|
|
436
436
|
params.push(castParameter(param.value, param.type))
|
|
437
437
|
}
|
|
438
|
+
} else {
|
|
439
|
+
for (const name in this.parameters) {
|
|
440
|
+
if (!objectHasProperty(this.parameters, name)) {
|
|
441
|
+
continue
|
|
442
|
+
}
|
|
443
|
+
const param = this.parameters[name]
|
|
444
|
+
if (param.io === 1 || (param.io === 2 && param.value != null)) {
|
|
445
|
+
params.push(castParameter(param.value, param.type))
|
|
446
|
+
}
|
|
447
|
+
}
|
|
438
448
|
}
|
|
439
449
|
|
|
440
450
|
debug('request(%d): query', IDS.get(this), command)
|
|
@@ -726,6 +736,10 @@ class Request extends BaseRequest {
|
|
|
726
736
|
return callback(new RequestError(e, 'EREQUEST'))
|
|
727
737
|
}
|
|
728
738
|
|
|
739
|
+
// the parameters in the order their markers are written: output initial values are set
|
|
740
|
+
// before the call and inputs are passed to it, whatever order they were declared in
|
|
741
|
+
const bound = []
|
|
742
|
+
|
|
729
743
|
// set output params w/ values
|
|
730
744
|
const sets = []
|
|
731
745
|
for (const name in this.parameters) {
|
|
@@ -733,8 +747,9 @@ class Request extends BaseRequest {
|
|
|
733
747
|
continue
|
|
734
748
|
}
|
|
735
749
|
const param = this.parameters[name]
|
|
736
|
-
if (param.io === 2 && param.value) {
|
|
750
|
+
if (param.io === 2 && param.value != null) {
|
|
737
751
|
sets.push(`set @${param.name}=?`)
|
|
752
|
+
bound.push(param)
|
|
738
753
|
}
|
|
739
754
|
}
|
|
740
755
|
|
|
@@ -754,6 +769,7 @@ class Request extends BaseRequest {
|
|
|
754
769
|
} else {
|
|
755
770
|
// input parameter
|
|
756
771
|
spp.push(`@${param.name}=?`)
|
|
772
|
+
bound.push(param)
|
|
757
773
|
}
|
|
758
774
|
}
|
|
759
775
|
|
|
@@ -829,7 +845,7 @@ class Request extends BaseRequest {
|
|
|
829
845
|
} else {
|
|
830
846
|
callback(null, recordsets, output, returnValue, rowsAffected, recordsetcolumns)
|
|
831
847
|
}
|
|
832
|
-
})
|
|
848
|
+
}, bound)
|
|
833
849
|
})
|
|
834
850
|
}
|
|
835
851
|
|
package/lib/tedious/request.js
CHANGED
|
@@ -12,6 +12,7 @@ const { valueHandler } = require('../shared')
|
|
|
12
12
|
|
|
13
13
|
const JSON_COLUMN_ID = 'JSON_F52E2B61-18A1-11d1-B105-00805F49916B'
|
|
14
14
|
const XML_COLUMN_ID = 'XML_F52E2B61-18A1-11d1-B105-00805F49916B'
|
|
15
|
+
const MAX = 65535 // (1 << 16) - 1
|
|
15
16
|
|
|
16
17
|
const N_TYPES = {
|
|
17
18
|
BitN: 0x68,
|
|
@@ -174,6 +175,18 @@ const valueCorrection = function (value, metadata) {
|
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
|
|
178
|
+
// tedious only compares a length as a number, so `max` is passed as the length it stands
|
|
179
|
+
// for. As a word it compares false against the type's maximum both ways, and tedious then
|
|
180
|
+
// writes a `max` value without its terminator.
|
|
181
|
+
const tediousLength = function (length) {
|
|
182
|
+
return typeof length === 'string' && length.trim().toLowerCase() === 'max' ? MAX : length
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// tedious writes a TVP column with the length it is given, without resolving a missing one,
|
|
186
|
+
// and a missing length fails the same comparisons as `max`. These types are given `max`,
|
|
187
|
+
// which is how tedious wrote them before it compared the length both ways.
|
|
188
|
+
const MAX_LENGTH_TYPES = new Set([tds.TYPES.NVarChar, tds.TYPES.VarChar, tds.TYPES.VarBinary])
|
|
189
|
+
|
|
177
190
|
const parameterCorrection = function (value) {
|
|
178
191
|
if (value instanceof Table) {
|
|
179
192
|
const tvp = {
|
|
@@ -191,7 +204,7 @@ const parameterCorrection = function (value) {
|
|
|
191
204
|
tvp.columns.push({
|
|
192
205
|
name: col.name,
|
|
193
206
|
type: tediousType,
|
|
194
|
-
length: col.length,
|
|
207
|
+
length: col.length == null && MAX_LENGTH_TYPES.has(tediousType) ? MAX : tediousLength(col.length),
|
|
195
208
|
scale: col.scale,
|
|
196
209
|
precision: col.precision
|
|
197
210
|
})
|
|
@@ -368,7 +381,7 @@ class Request extends BaseRequest {
|
|
|
368
381
|
// tedious emits this name as a quoted identifier of its own when it builds
|
|
369
382
|
// the `insert bulk` statement, so it is checked here as well as in
|
|
370
383
|
// Table#declare, in case the name changed since it was checked above.
|
|
371
|
-
bulk.addColumn(assertSafeColumnName(col.name), getTediousType(col.type), { nullable: col.nullable, length: assertSafeTypeSize(col.length), scale: assertSafeTypeSize(col.scale), precision: assertSafeTypeSize(col.precision) })
|
|
384
|
+
bulk.addColumn(assertSafeColumnName(col.name), getTediousType(col.type), { nullable: col.nullable, length: tediousLength(assertSafeTypeSize(col.length)), scale: assertSafeTypeSize(col.scale), precision: assertSafeTypeSize(col.precision) })
|
|
372
385
|
}
|
|
373
386
|
|
|
374
387
|
if (table.create) {
|
|
@@ -773,9 +786,9 @@ class Request extends BaseRequest {
|
|
|
773
786
|
// tedious builds the sp_executesql declaration from these, so a rejected size
|
|
774
787
|
// has to be reported through the path that releases the connection
|
|
775
788
|
if (param.io === 1) {
|
|
776
|
-
req.addParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), { length: assertSafeTypeSize(param.length), scale: assertSafeTypeSize(param.scale), precision: assertSafeTypeSize(param.precision) })
|
|
789
|
+
req.addParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), { length: tediousLength(assertSafeTypeSize(param.length)), scale: assertSafeTypeSize(param.scale), precision: assertSafeTypeSize(param.precision) })
|
|
777
790
|
} else {
|
|
778
|
-
req.addOutputParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), { length: assertSafeTypeSize(param.length), scale: assertSafeTypeSize(param.scale), precision: assertSafeTypeSize(param.precision) })
|
|
791
|
+
req.addOutputParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), { length: tediousLength(assertSafeTypeSize(param.length)), scale: assertSafeTypeSize(param.scale), precision: assertSafeTypeSize(param.precision) })
|
|
779
792
|
}
|
|
780
793
|
}
|
|
781
794
|
}
|
|
@@ -1093,9 +1106,9 @@ class Request extends BaseRequest {
|
|
|
1093
1106
|
}
|
|
1094
1107
|
const param = this.parameters[name]
|
|
1095
1108
|
if (param.io === 1) {
|
|
1096
|
-
req.addParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), { length: assertSafeTypeSize(param.length), scale: assertSafeTypeSize(param.scale), precision: assertSafeTypeSize(param.precision) })
|
|
1109
|
+
req.addParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), { length: tediousLength(assertSafeTypeSize(param.length)), scale: assertSafeTypeSize(param.scale), precision: assertSafeTypeSize(param.precision) })
|
|
1097
1110
|
} else {
|
|
1098
|
-
req.addOutputParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), { length: assertSafeTypeSize(param.length), scale: assertSafeTypeSize(param.scale), precision: assertSafeTypeSize(param.precision) })
|
|
1111
|
+
req.addOutputParameter(param.name, getTediousType(param.type), parameterCorrection(param.value), { length: tediousLength(assertSafeTypeSize(param.length)), scale: assertSafeTypeSize(param.scale), precision: assertSafeTypeSize(param.precision) })
|
|
1099
1112
|
}
|
|
1100
1113
|
}
|
|
1101
1114
|
|