mssql 12.7.5 → 12.7.6
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 +2 -0
- package/lib/table.js +4 -0
- package/lib/tedious/request.js +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1213,6 +1213,8 @@ request.bulk(table, (err, result) => {
|
|
|
1213
1213
|
|
|
1214
1214
|
**TIP**: You can also create Table variable from any recordset with `recordset.toTable()`. You can optionally specify table type name in the first argument.
|
|
1215
1215
|
|
|
1216
|
+
**TIP**: A `VarChar`, `NVarChar` or `VarBinary` column declared without a length (e.g. `sql.NVarChar`) is created as `max` when `table.create` is set, and the tedious driver loads it as `max`. It does so whether or not the table already existed, so when `table.create` is set for an existing table, give such a column its length if the table's column is sized (it loads faster) or a `sql_variant` (which cannot hold a `max` value). Without `table.create`, the tedious driver needs a column declared as `max` (e.g. `sql.NVarChar(sql.MAX)`) to bulk load into an existing `varchar(max)`, `nvarchar(max)` or `varbinary(max)` column. `Xml`, `UDT`, `Geography` and `Geometry` columns are loaded as `max` unless you give them a length.
|
|
1217
|
+
|
|
1216
1218
|
__Errors__
|
|
1217
1219
|
- ENAME (`RequestError`) - Table name must be specified for bulk insert.
|
|
1218
1220
|
- ETIMEOUT (`RequestError`) - Request timeout.
|
package/lib/table.js
CHANGED
|
@@ -80,14 +80,18 @@ Table.prototype._makeBulk = function _makeBulk () {
|
|
|
80
80
|
}
|
|
81
81
|
break
|
|
82
82
|
|
|
83
|
+
// these are sent as `max` values, so a column without a length is given `max`, which
|
|
84
|
+
// is how Table#declare creates it anyway
|
|
83
85
|
case TYPES.Xml:
|
|
84
86
|
col.type = TYPES.NVarChar(MAX).type
|
|
87
|
+
if (col.length == null) col.length = MAX
|
|
85
88
|
break
|
|
86
89
|
|
|
87
90
|
case TYPES.UDT:
|
|
88
91
|
case TYPES.Geography:
|
|
89
92
|
case TYPES.Geometry:
|
|
90
93
|
col.type = TYPES.VarBinary(MAX).type
|
|
94
|
+
if (col.length == null) col.length = MAX
|
|
91
95
|
break
|
|
92
96
|
|
|
93
97
|
default:
|
package/lib/tedious/request.js
CHANGED
|
@@ -378,10 +378,17 @@ class Request extends BaseRequest {
|
|
|
378
378
|
}
|
|
379
379
|
bulk = connection.newBulkLoad(table.path, bulkOptions, done)
|
|
380
380
|
for (const col of table.columns) {
|
|
381
|
+
const type = getTediousType(col.type)
|
|
382
|
+
// tedious resolves a missing length to 4000 or 8000, but Table#declare creates
|
|
383
|
+
// such a column as `max`, and the server will not load a sized column into a
|
|
384
|
+
// `max` one, so with table.create the column is sent as `max`, even when the
|
|
385
|
+
// table turns out to exist already. Without it the target's column types are
|
|
386
|
+
// not known here, so the column keeps the length tedious gives it.
|
|
387
|
+
const length = assertSafeTypeSize(col.length)
|
|
381
388
|
// tedious emits this name as a quoted identifier of its own when it builds
|
|
382
389
|
// the `insert bulk` statement, so it is checked here as well as in
|
|
383
390
|
// Table#declare, in case the name changed since it was checked above.
|
|
384
|
-
bulk.addColumn(assertSafeColumnName(col.name),
|
|
391
|
+
bulk.addColumn(assertSafeColumnName(col.name), type, { nullable: col.nullable, length: length == null && table.create && MAX_LENGTH_TYPES.has(type) ? MAX : tediousLength(length), scale: assertSafeTypeSize(col.scale), precision: assertSafeTypeSize(col.precision) })
|
|
385
392
|
}
|
|
386
393
|
|
|
387
394
|
if (table.create) {
|