mssql 12.7.10 → 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 +2 -0
- package/lib/msnodesqlv8/request.js +26 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2318,6 +2318,8 @@ Columns structure for example above:
|
|
|
2318
2318
|
}
|
|
2319
2319
|
```
|
|
2320
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
|
+
|
|
2321
2323
|
## Data Types
|
|
2322
2324
|
|
|
2323
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
|
}
|
|
@@ -743,13 +762,13 @@ class Request extends BaseRequest {
|
|
|
743
762
|
|
|
744
763
|
row = null
|
|
745
764
|
rowsInRecordset = 0
|
|
746
|
-
columns = metadata
|
|
765
|
+
columns = metadata.map(describeColumn)
|
|
747
766
|
recordset = []
|
|
748
767
|
|
|
749
768
|
Object.defineProperty(recordset, 'columns', {
|
|
750
769
|
enumerable: false,
|
|
751
770
|
configurable: true,
|
|
752
|
-
value: createColumns(
|
|
771
|
+
value: createColumns(columns, this.arrayRowMode)
|
|
753
772
|
})
|
|
754
773
|
|
|
755
774
|
Object.defineProperty(recordset, 'toTable', {
|