mssql 12.7.9 → 12.7.11
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 +6 -1
- package/lib/msnodesqlv8/request.js +30 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1550,6 +1550,7 @@ __Errors__
|
|
|
1550
1550
|
- ECONNCLOSED (`ConnectionError`) - Connection is closed.
|
|
1551
1551
|
- EALREADYPREPARED (`PreparedStatementError`) - Statement is already prepared.
|
|
1552
1552
|
- ENOTBEGUN (`TransactionError`) - Transaction has not begun.
|
|
1553
|
+
- EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
|
|
1553
1554
|
|
|
1554
1555
|
---------------------------------------
|
|
1555
1556
|
|
|
@@ -1626,6 +1627,7 @@ __Errors__
|
|
|
1626
1627
|
- EREQUEST (`RequestError`) - *Message from SQL Server*
|
|
1627
1628
|
- EPARAM (`RequestError`) - A parameter value is not valid for its type.
|
|
1628
1629
|
- ECANCEL (`RequestError`) - Cancelled.
|
|
1630
|
+
- EREQINPROG (`TransactionError`) - Can't acquire connection for the request. There is another request in progress.
|
|
1629
1631
|
|
|
1630
1632
|
---------------------------------------
|
|
1631
1633
|
|
|
@@ -1654,6 +1656,7 @@ ps.prepare('select @param as value', err => {
|
|
|
1654
1656
|
|
|
1655
1657
|
__Errors__
|
|
1656
1658
|
- ENOTPREPARED (`PreparedStatementError`) - Statement is not prepared.
|
|
1659
|
+
- EREQINPROG (`TransactionError`) - Can't unprepare the statement. There is a request in progress.
|
|
1657
1660
|
|
|
1658
1661
|
## CLI
|
|
1659
1662
|
|
|
@@ -2222,7 +2225,7 @@ Name | Code | Message
|
|
|
2222
2225
|
`ConnectionError` | ECONNCLOSED | Connection is closed.
|
|
2223
2226
|
`TransactionError` | ENOTBEGUN | Transaction has not begun.
|
|
2224
2227
|
`TransactionError` | EALREADYBEGUN | Transaction has already begun.
|
|
2225
|
-
`TransactionError` | EREQINPROG | Can't commit/rollback transaction or acquire connection for the request. There is a request in progress.
|
|
2228
|
+
`TransactionError` | EREQINPROG | Can't commit/rollback transaction, unprepare the statement or acquire connection for the request. There is a request in progress.
|
|
2226
2229
|
`TransactionError` | EABORT | Transaction has been aborted.
|
|
2227
2230
|
`TransactionError` | ENOCONN | No connection is specified for that transaction.
|
|
2228
2231
|
`RequestError` | EREQUEST | Message from SQL Server. Error object contains additional details.
|
|
@@ -2315,6 +2318,8 @@ Columns structure for example above:
|
|
|
2315
2318
|
}
|
|
2316
2319
|
```
|
|
2317
2320
|
|
|
2321
|
+
The MSNodeSQLv8 driver describes a column only by `index`, `name`, `length`, `type`, `nullable` and `identity` (and `udt.name` for a CLR type); it has no `scale`, `precision`, `caseSensitive` or `readOnly` to give. Its `length` is the size ODBC reports for the column, which for a number is its precision rather than its length in bytes. ODBC names the type of a column of an alias type (`CREATE TYPE dbo.MyInt FROM int`) after the alias, so with this driver such a column has no `type`, and is not marked as an `identity` column even when it is one.
|
|
2322
|
+
|
|
2318
2323
|
## Data Types
|
|
2319
2324
|
|
|
2320
2325
|
You can define data types with length/precision/scale:
|
|
@@ -111,6 +111,18 @@ const castParameter = function (value, type) {
|
|
|
111
111
|
return value
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
// ODBC names the type of an identity column after the type it holds, as 'int identity', and
|
|
115
|
+
// gives decimal and numeric the brackets of their precision, as 'decimal() identity'
|
|
116
|
+
const IDENTITY_SQL_TYPE = /^(tinyint|smallint|int|bigint|decimal|numeric)(?:\(\))? identity$/
|
|
117
|
+
|
|
118
|
+
// msnodesqlv8 describes a column by the name ODBC gives its type. An identity column is described
|
|
119
|
+
// by the type it holds instead, so that it is described, and its values read, as any other column
|
|
120
|
+
// of that type.
|
|
121
|
+
const describeColumn = function (column) {
|
|
122
|
+
const identity = typeof column.sqlType === 'string' ? IDENTITY_SQL_TYPE.exec(column.sqlType) : null
|
|
123
|
+
return identity ? { ...column, sqlType: identity[1], identity: true } : column
|
|
124
|
+
}
|
|
125
|
+
|
|
114
126
|
const createColumns = function (metadata, arrayRowMode) {
|
|
115
127
|
let out = {}
|
|
116
128
|
if (arrayRowMode) out = []
|
|
@@ -122,7 +134,8 @@ const createColumns = function (metadata, arrayRowMode) {
|
|
|
122
134
|
name: column.name,
|
|
123
135
|
length: column.size,
|
|
124
136
|
type: DECLARATIONS[column.sqlType],
|
|
125
|
-
nullable: column.nullable
|
|
137
|
+
nullable: column.nullable,
|
|
138
|
+
identity: column.identity === true
|
|
126
139
|
}
|
|
127
140
|
|
|
128
141
|
if (column.udtType != null) {
|
|
@@ -147,6 +160,16 @@ const createColumns = function (metadata, arrayRowMode) {
|
|
|
147
160
|
const numericStringSqlTypes = new Set(['int', 'smallint', 'tinyint', 'float', 'real', 'numeric', 'decimal', 'money', 'smallmoney'])
|
|
148
161
|
|
|
149
162
|
const valueCorrection = function (value, metadata) {
|
|
163
|
+
// a number msnodesqlv8 hands over as a string is read as a number before a value handler is
|
|
164
|
+
// given it, as it is with the tedious driver
|
|
165
|
+
if (typeof value === 'string') {
|
|
166
|
+
if (numericStringSqlTypes.has(metadata.sqlType)) {
|
|
167
|
+
value = Number(value)
|
|
168
|
+
} else if (metadata.sqlType === 'sql_variant' && value !== '' && !isNaN(Number(value))) {
|
|
169
|
+
value = Number(value)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
150
173
|
const type = metadata && objectHasProperty(metadata, 'sqlType') && objectHasProperty(DECLARATIONS, metadata.sqlType)
|
|
151
174
|
? DECLARATIONS[metadata.sqlType]
|
|
152
175
|
: null
|
|
@@ -161,10 +184,6 @@ const valueCorrection = function (value, metadata) {
|
|
|
161
184
|
} else {
|
|
162
185
|
return value
|
|
163
186
|
}
|
|
164
|
-
} else if (typeof value === 'string' && numericStringSqlTypes.has(metadata.sqlType)) {
|
|
165
|
-
return Number(value)
|
|
166
|
-
} else if (typeof value === 'string' && metadata.sqlType === 'sql_variant' && value !== '' && !isNaN(Number(value))) {
|
|
167
|
-
return Number(value)
|
|
168
187
|
} else {
|
|
169
188
|
return value
|
|
170
189
|
}
|
|
@@ -701,6 +720,10 @@ class Request extends BaseRequest {
|
|
|
701
720
|
cancelHeld = false
|
|
702
721
|
cancel()
|
|
703
722
|
}
|
|
723
|
+
// a stream resumed meanwhile left the query held back. msnodesqlv8 fetches as soon as
|
|
724
|
+
// it is resumed, and again once 'meta' is handled, so the query is resumed a tick
|
|
725
|
+
// later, once it has stopped at the result set
|
|
726
|
+
if (!this.paused && driverPaused && !cancelRequested) setImmediate(this._resumeStream)
|
|
704
727
|
}
|
|
705
728
|
|
|
706
729
|
if (row) {
|
|
@@ -739,13 +762,13 @@ class Request extends BaseRequest {
|
|
|
739
762
|
|
|
740
763
|
row = null
|
|
741
764
|
rowsInRecordset = 0
|
|
742
|
-
columns = metadata
|
|
765
|
+
columns = metadata.map(describeColumn)
|
|
743
766
|
recordset = []
|
|
744
767
|
|
|
745
768
|
Object.defineProperty(recordset, 'columns', {
|
|
746
769
|
enumerable: false,
|
|
747
770
|
configurable: true,
|
|
748
|
-
value: createColumns(
|
|
771
|
+
value: createColumns(columns, this.arrayRowMode)
|
|
749
772
|
})
|
|
750
773
|
|
|
751
774
|
Object.defineProperty(recordset, 'toTable', {
|