tedious 6.4.0 → 6.6.2
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/bulk-load.js +17 -22
- package/lib/connection.js +363 -251
- package/lib/connector.js +3 -1
- package/lib/data-type.js +111 -109
- package/lib/data-types/bigint.js +19 -7
- package/lib/data-types/binary.js +19 -10
- package/lib/data-types/bit.js +14 -4
- package/lib/data-types/bitn.js +26 -3
- package/lib/data-types/char.js +26 -13
- package/lib/data-types/date.js +18 -9
- package/lib/data-types/datetime.js +23 -5
- package/lib/data-types/datetime2.js +10 -22
- package/lib/data-types/datetimen.js +26 -3
- package/lib/data-types/datetimeoffset.js +11 -22
- package/lib/data-types/decimal.js +14 -6
- package/lib/data-types/decimaln.js +26 -5
- package/lib/data-types/float.js +14 -4
- package/lib/data-types/floatn.js +26 -3
- package/lib/data-types/image.js +12 -5
- package/lib/data-types/int.js +14 -4
- package/lib/data-types/intn.js +26 -3
- package/lib/data-types/money.js +14 -4
- package/lib/data-types/moneyn.js +26 -3
- package/lib/data-types/nchar.js +17 -6
- package/lib/data-types/ntext.js +26 -5
- package/lib/data-types/null.js +27 -3
- package/lib/data-types/numeric.js +14 -6
- package/lib/data-types/numericn.js +26 -5
- package/lib/data-types/nvarchar.js +20 -11
- package/lib/data-types/real.js +14 -4
- package/lib/data-types/smalldatetime.js +14 -4
- package/lib/data-types/smallint.js +14 -4
- package/lib/data-types/smallmoney.js +14 -4
- package/lib/data-types/sql-variant.js +23 -4
- package/lib/data-types/text.js +13 -7
- package/lib/data-types/time.js +9 -21
- package/lib/data-types/tinyint.js +14 -4
- package/lib/data-types/tvp.js +12 -3
- package/lib/data-types/udt.js +26 -3
- package/lib/data-types/uniqueidentifier.js +12 -5
- package/lib/data-types/varbinary.js +18 -8
- package/lib/data-types/varchar.js +19 -10
- package/lib/data-types/xml.js +26 -3
- package/lib/debug.js +3 -1
- package/lib/guid-parser.js +6 -6
- package/lib/incoming-message-stream.js +10 -7
- package/lib/instance-lookup.js +12 -6
- package/lib/library.js +6 -1
- package/lib/login7-payload.js +2 -3
- package/lib/message-io.js +14 -3
- package/lib/message.js +2 -3
- package/lib/metadata-parser.js +259 -136
- package/lib/ntlm-payload.js +12 -21
- package/lib/outgoing-message-stream.js +7 -6
- package/lib/packet.js +4 -5
- package/lib/prelogin-payload.js +3 -4
- package/lib/request.js +11 -11
- package/lib/rpcrequest-payload.js +28 -22
- package/lib/sender.js +25 -11
- package/lib/special-stored-procedure.js +9 -2
- package/lib/tds-versions.js +8 -2
- package/lib/tedious.js +75 -9
- package/lib/token/colmetadata-token-parser.js +20 -10
- package/lib/token/done-token-parser.js +32 -25
- package/lib/token/env-change-token-parser.js +50 -20
- package/lib/token/feature-ext-ack-parser.js +19 -14
- package/lib/token/fedauth-info-parser.js +17 -11
- package/lib/token/infoerror-token-parser.js +14 -14
- package/lib/token/loginack-token-parser.js +21 -12
- package/lib/token/nbcrow-token-parser.js +35 -23
- package/lib/token/order-token-parser.js +14 -7
- package/lib/token/returnstatus-token-parser.js +14 -7
- package/lib/token/returnvalue-token-parser.js +22 -11
- package/lib/token/row-token-parser.js +34 -22
- package/lib/token/sspi-token-parser.js +14 -8
- package/lib/token/stream-parser.js +95 -36
- package/lib/token/token-stream-parser.js +16 -10
- package/lib/token/token.js +396 -2
- package/lib/tracking-buffer/writable-tracking-buffer.js +37 -5
- package/lib/transaction.js +25 -16
- package/lib/transient-error-lookup.js +6 -1
- package/lib/value-parser.js +412 -315
- package/package.json +24 -21
- package/pull_request_template.md +1 -1
- package/tsconfig.json +1 -1
- package/lib/tracking-buffer/bigint.js +0 -102
package/lib/value-parser.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
var _metadataParser = require("./metadata-parser");
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
var _dataType = require("./data-type");
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
var _iconvLite = _interopRequireDefault(require("iconv-lite"));
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
var _sprintfJs = require("sprintf-js");
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
var _guidParser = require("./guid-parser");
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const convertLEBytesToString = require('./tracking-buffer/bigint').convertLEBytesToString;
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
19
|
|
|
19
20
|
const NULL = (1 << 16) - 1;
|
|
20
21
|
const MAX = (1 << 16) - 1;
|
|
@@ -24,228 +25,402 @@ const PLP_NULL = Buffer.from([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
|
|
|
24
25
|
const UNKNOWN_PLP_LEN = Buffer.from([0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
|
|
25
26
|
const DEFAULT_ENCODING = 'utf8';
|
|
26
27
|
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
function readTinyInt(parser, callback) {
|
|
29
|
+
parser.readUInt8(callback);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function readSmallInt(parser, callback) {
|
|
33
|
+
parser.readInt16LE(callback);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function readInt(parser, callback) {
|
|
37
|
+
parser.readInt32LE(callback);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function readBigInt(parser, callback) {
|
|
41
|
+
parser.readBigInt64LE(value => {
|
|
42
|
+
callback(value.toString());
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function readReal(parser, callback) {
|
|
47
|
+
parser.readFloatLE(callback);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readFloat(parser, callback) {
|
|
51
|
+
parser.readDoubleLE(callback);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function readSmallMoney(parser, callback) {
|
|
55
|
+
parser.readInt32LE(value => {
|
|
56
|
+
callback(value / MONEY_DIVISOR);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function readMoney(parser, callback) {
|
|
61
|
+
parser.readInt32LE(high => {
|
|
62
|
+
parser.readUInt32LE(low => {
|
|
63
|
+
callback((low + 0x100000000 * high) / MONEY_DIVISOR);
|
|
40
64
|
});
|
|
41
|
-
}
|
|
42
|
-
callback(undefined);
|
|
43
|
-
}
|
|
65
|
+
});
|
|
44
66
|
}
|
|
45
67
|
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
68
|
+
function readBit(parser, callback) {
|
|
69
|
+
parser.readUInt8(value => {
|
|
70
|
+
callback(!!value);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function valueParse(parser, metadata, options, callback) {
|
|
75
|
+
const type = metadata.type;
|
|
76
|
+
|
|
77
|
+
switch (type.name) {
|
|
78
|
+
case 'Null':
|
|
79
|
+
return callback(null);
|
|
80
|
+
|
|
81
|
+
case 'TinyInt':
|
|
82
|
+
return readTinyInt(parser, callback);
|
|
50
83
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
} // s2.2.4.2.1
|
|
84
|
+
case 'SmallInt':
|
|
85
|
+
return readSmallInt(parser, callback);
|
|
54
86
|
|
|
87
|
+
case 'Int':
|
|
88
|
+
return readInt(parser, callback);
|
|
55
89
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// xx01xxxx - s2.2.4.2.1.1
|
|
59
|
-
return callback(0);
|
|
90
|
+
case 'BigInt':
|
|
91
|
+
return readBigInt(parser, callback);
|
|
60
92
|
|
|
61
|
-
case
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
if (metaData.dataLength !== MAX) {
|
|
65
|
-
switch (type.dataLengthLength) {
|
|
93
|
+
case 'IntN':
|
|
94
|
+
return parser.readUInt8(dataLength => {
|
|
95
|
+
switch (dataLength) {
|
|
66
96
|
case 0:
|
|
67
|
-
return callback(
|
|
97
|
+
return callback(null);
|
|
68
98
|
|
|
69
99
|
case 1:
|
|
70
|
-
return parser
|
|
100
|
+
return readTinyInt(parser, callback);
|
|
71
101
|
|
|
72
102
|
case 2:
|
|
73
|
-
return parser
|
|
103
|
+
return readSmallInt(parser, callback);
|
|
74
104
|
|
|
75
105
|
case 4:
|
|
76
|
-
return parser
|
|
106
|
+
return readInt(parser, callback);
|
|
107
|
+
|
|
108
|
+
case 8:
|
|
109
|
+
return readBigInt(parser, callback);
|
|
77
110
|
|
|
78
111
|
default:
|
|
79
|
-
return parser.emit('error', new Error('Unsupported
|
|
112
|
+
return parser.emit('error', new Error('Unsupported dataLength ' + dataLength + ' for IntN'));
|
|
80
113
|
}
|
|
81
|
-
}
|
|
82
|
-
return callback(undefined);
|
|
83
|
-
}
|
|
114
|
+
});
|
|
84
115
|
|
|
85
|
-
case
|
|
86
|
-
return
|
|
87
|
-
}
|
|
88
|
-
}
|
|
116
|
+
case 'Real':
|
|
117
|
+
return readReal(parser, callback);
|
|
89
118
|
|
|
90
|
-
|
|
119
|
+
case 'Float':
|
|
120
|
+
return readFloat(parser, callback);
|
|
91
121
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
case 'Null':
|
|
98
|
-
return callback(null);
|
|
122
|
+
case 'FloatN':
|
|
123
|
+
return parser.readUInt8(dataLength => {
|
|
124
|
+
switch (dataLength) {
|
|
125
|
+
case 0:
|
|
126
|
+
return callback(null);
|
|
99
127
|
|
|
100
|
-
|
|
101
|
-
|
|
128
|
+
case 4:
|
|
129
|
+
return readReal(parser, callback);
|
|
102
130
|
|
|
103
|
-
|
|
104
|
-
|
|
131
|
+
case 8:
|
|
132
|
+
return readFloat(parser, callback);
|
|
105
133
|
|
|
106
|
-
|
|
107
|
-
|
|
134
|
+
default:
|
|
135
|
+
return parser.emit('error', new Error('Unsupported dataLength ' + dataLength + ' for FloatN'));
|
|
136
|
+
}
|
|
137
|
+
});
|
|
108
138
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
callback(convertLEBytesToString(buffer));
|
|
112
|
-
});
|
|
139
|
+
case 'SmallMoney':
|
|
140
|
+
return readSmallMoney(parser, callback);
|
|
113
141
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
case 0:
|
|
117
|
-
return callback(null);
|
|
142
|
+
case 'Money':
|
|
143
|
+
return readMoney(parser, callback);
|
|
118
144
|
|
|
119
|
-
|
|
120
|
-
|
|
145
|
+
case 'MoneyN':
|
|
146
|
+
return parser.readUInt8(dataLength => {
|
|
147
|
+
switch (dataLength) {
|
|
148
|
+
case 0:
|
|
149
|
+
return callback(null);
|
|
121
150
|
|
|
122
|
-
|
|
123
|
-
|
|
151
|
+
case 4:
|
|
152
|
+
return readSmallMoney(parser, callback);
|
|
124
153
|
|
|
125
|
-
|
|
126
|
-
|
|
154
|
+
case 8:
|
|
155
|
+
return readMoney(parser, callback);
|
|
127
156
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
157
|
+
default:
|
|
158
|
+
return parser.emit('error', new Error('Unsupported dataLength ' + dataLength + ' for MoneyN'));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
132
161
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
162
|
+
case 'Bit':
|
|
163
|
+
return readBit(parser, callback);
|
|
136
164
|
|
|
137
|
-
|
|
138
|
-
|
|
165
|
+
case 'BitN':
|
|
166
|
+
return parser.readUInt8(dataLength => {
|
|
167
|
+
switch (dataLength) {
|
|
168
|
+
case 0:
|
|
169
|
+
return callback(null);
|
|
139
170
|
|
|
140
|
-
|
|
141
|
-
|
|
171
|
+
case 1:
|
|
172
|
+
return readBit(parser, callback);
|
|
142
173
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
174
|
+
default:
|
|
175
|
+
return parser.emit('error', new Error('Unsupported dataLength ' + dataLength + ' for BitN'));
|
|
176
|
+
}
|
|
177
|
+
});
|
|
147
178
|
|
|
148
|
-
|
|
149
|
-
|
|
179
|
+
case 'VarChar':
|
|
180
|
+
case 'Char':
|
|
181
|
+
const codepage = metadata.collation.codepage;
|
|
150
182
|
|
|
151
|
-
|
|
152
|
-
|
|
183
|
+
if (metadata.dataLength === MAX) {
|
|
184
|
+
return readMaxChars(parser, codepage, callback);
|
|
185
|
+
} else {
|
|
186
|
+
return parser.readUInt16LE(dataLength => {
|
|
187
|
+
if (dataLength === NULL) {
|
|
188
|
+
return callback(null);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
readChars(parser, dataLength, codepage, callback);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
153
194
|
|
|
154
|
-
|
|
155
|
-
|
|
195
|
+
case 'NVarChar':
|
|
196
|
+
case 'NChar':
|
|
197
|
+
if (metadata.dataLength === MAX) {
|
|
198
|
+
return readMaxNChars(parser, callback);
|
|
199
|
+
} else {
|
|
200
|
+
return parser.readUInt16LE(dataLength => {
|
|
201
|
+
if (dataLength === NULL) {
|
|
202
|
+
return callback(null);
|
|
156
203
|
}
|
|
157
204
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
case 8:
|
|
171
|
-
return parser.readInt32LE(high => {
|
|
172
|
-
parser.readUInt32LE(low => {
|
|
173
|
-
callback((low + 0x100000000 * high) / MONEY_DIVISOR);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
default:
|
|
178
|
-
return parser.emit('error', new Error('Unsupported dataLength ' + dataLength + ' for MoneyN'));
|
|
205
|
+
readNChars(parser, dataLength, callback);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
case 'VarBinary':
|
|
210
|
+
case 'Binary':
|
|
211
|
+
if (metadata.dataLength === MAX) {
|
|
212
|
+
return readMaxBinary(parser, callback);
|
|
213
|
+
} else {
|
|
214
|
+
return parser.readUInt16LE(dataLength => {
|
|
215
|
+
if (dataLength === NULL) {
|
|
216
|
+
return callback(null);
|
|
179
217
|
}
|
|
180
218
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
219
|
+
readBinary(parser, dataLength, callback);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
case 'Text':
|
|
224
|
+
return parser.readUInt8(textPointerLength => {
|
|
225
|
+
if (textPointerLength === 0) {
|
|
226
|
+
return callback(null);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
parser.readBuffer(textPointerLength, _textPointer => {
|
|
230
|
+
parser.readBuffer(8, _timestamp => {
|
|
231
|
+
parser.readUInt32LE(dataLength => {
|
|
232
|
+
readChars(parser, dataLength, metadata.collation.codepage, callback);
|
|
233
|
+
});
|
|
184
234
|
});
|
|
235
|
+
});
|
|
236
|
+
});
|
|
185
237
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
238
|
+
case 'NText':
|
|
239
|
+
return parser.readUInt8(textPointerLength => {
|
|
240
|
+
if (textPointerLength === 0) {
|
|
241
|
+
return callback(null);
|
|
242
|
+
}
|
|
190
243
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
244
|
+
parser.readBuffer(textPointerLength, _textPointer => {
|
|
245
|
+
parser.readBuffer(8, _timestamp => {
|
|
246
|
+
parser.readUInt32LE(dataLength => {
|
|
247
|
+
readNChars(parser, dataLength, callback);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
});
|
|
195
252
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
253
|
+
case 'Image':
|
|
254
|
+
return parser.readUInt8(textPointerLength => {
|
|
255
|
+
if (textPointerLength === 0) {
|
|
256
|
+
return callback(null);
|
|
257
|
+
}
|
|
199
258
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
259
|
+
parser.readBuffer(textPointerLength, _textPointer => {
|
|
260
|
+
parser.readBuffer(8, _timestamp => {
|
|
261
|
+
parser.readUInt32LE(dataLength => {
|
|
262
|
+
readBinary(parser, dataLength, callback);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
});
|
|
203
267
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
} else {
|
|
207
|
-
return readChars(parser, dataLength, codepage, NULL, callback);
|
|
208
|
-
}
|
|
268
|
+
case 'Xml':
|
|
269
|
+
return readMaxNChars(parser, callback);
|
|
209
270
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (metaData.dataLength === MAX) {
|
|
213
|
-
return readMaxNChars(parser, callback);
|
|
214
|
-
} else {
|
|
215
|
-
return readNChars(parser, dataLength, NULL, callback);
|
|
216
|
-
}
|
|
271
|
+
case 'SmallDateTime':
|
|
272
|
+
return readSmallDateTime(parser, options.useUTC, callback);
|
|
217
273
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (metaData.dataLength === MAX) {
|
|
221
|
-
return readMaxBinary(parser, callback);
|
|
222
|
-
} else {
|
|
223
|
-
return readBinary(parser, dataLength, NULL, callback);
|
|
224
|
-
}
|
|
274
|
+
case 'DateTime':
|
|
275
|
+
return readDateTime(parser, options.useUTC, callback);
|
|
225
276
|
|
|
226
|
-
|
|
227
|
-
|
|
277
|
+
case 'DateTimeN':
|
|
278
|
+
return parser.readUInt8(dataLength => {
|
|
279
|
+
switch (dataLength) {
|
|
280
|
+
case 0:
|
|
228
281
|
return callback(null);
|
|
229
|
-
} else {
|
|
230
|
-
return readChars(parser, dataLength, metaData.collation.codepage, PLP_NULL, callback);
|
|
231
|
-
}
|
|
232
282
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
return
|
|
238
|
-
}
|
|
283
|
+
case 4:
|
|
284
|
+
return readSmallDateTime(parser, options.useUTC, callback);
|
|
285
|
+
|
|
286
|
+
case 8:
|
|
287
|
+
return readDateTime(parser, options.useUTC, callback);
|
|
239
288
|
|
|
240
|
-
|
|
241
|
-
|
|
289
|
+
default:
|
|
290
|
+
return parser.emit('error', new Error('Unsupported dataLength ' + dataLength + ' for DateTimeN'));
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
case 'Time':
|
|
295
|
+
return parser.readUInt8(dataLength => {
|
|
296
|
+
if (dataLength === 0) {
|
|
297
|
+
return callback(null);
|
|
298
|
+
} else {
|
|
299
|
+
return readTime(parser, dataLength, metadata.scale, options.useUTC, callback);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
case 'Date':
|
|
304
|
+
return parser.readUInt8(dataLength => {
|
|
305
|
+
if (dataLength === 0) {
|
|
306
|
+
return callback(null);
|
|
307
|
+
} else {
|
|
308
|
+
return readDate(parser, options.useUTC, callback);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
case 'DateTime2':
|
|
313
|
+
return parser.readUInt8(dataLength => {
|
|
314
|
+
if (dataLength === 0) {
|
|
315
|
+
return callback(null);
|
|
316
|
+
} else {
|
|
317
|
+
return readDateTime2(parser, dataLength, metadata.scale, options.useUTC, callback);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
case 'DateTimeOffset':
|
|
322
|
+
return parser.readUInt8(dataLength => {
|
|
323
|
+
if (dataLength === 0) {
|
|
324
|
+
return callback(null);
|
|
325
|
+
} else {
|
|
326
|
+
return readDateTimeOffset(parser, dataLength, metadata.scale, callback);
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
case 'NumericN':
|
|
331
|
+
case 'DecimalN':
|
|
332
|
+
return parser.readUInt8(dataLength => {
|
|
333
|
+
if (dataLength === 0) {
|
|
334
|
+
return callback(null);
|
|
335
|
+
} else {
|
|
336
|
+
return readNumeric(parser, dataLength, metadata.precision, metadata.scale, callback);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
case 'UniqueIdentifier':
|
|
341
|
+
return parser.readUInt8(dataLength => {
|
|
342
|
+
switch (dataLength) {
|
|
343
|
+
case 0:
|
|
242
344
|
return callback(null);
|
|
243
|
-
} else {
|
|
244
|
-
return readBinary(parser, dataLength, PLP_NULL, callback);
|
|
245
|
-
}
|
|
246
345
|
|
|
247
|
-
|
|
248
|
-
|
|
346
|
+
case 0x10:
|
|
347
|
+
return readUniqueIdentifier(parser, options, callback);
|
|
348
|
+
|
|
349
|
+
default:
|
|
350
|
+
return parser.emit('error', new Error((0, _sprintfJs.sprintf)('Unsupported guid size %d', dataLength - 1)));
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
case 'UDT':
|
|
355
|
+
return readMaxBinary(parser, callback);
|
|
356
|
+
|
|
357
|
+
case 'Variant':
|
|
358
|
+
return parser.readUInt32LE(dataLength => {
|
|
359
|
+
if (dataLength === 0) {
|
|
360
|
+
return callback(null);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
readVariant(parser, options, dataLength, callback);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
default:
|
|
367
|
+
parser.emit('error', new Error((0, _sprintfJs.sprintf)('Unrecognised type %s', type.name)));
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function readUniqueIdentifier(parser, options, callback) {
|
|
372
|
+
parser.readBuffer(0x10, data => {
|
|
373
|
+
callback(options.lowerCaseGuids ? (0, _guidParser.bufferToLowerCaseGuid)(data) : (0, _guidParser.bufferToUpperCaseGuid)(data));
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function readNumeric(parser, dataLength, _precision, scale, callback) {
|
|
378
|
+
parser.readUInt8(sign => {
|
|
379
|
+
sign = sign === 1 ? 1 : -1;
|
|
380
|
+
let readValue;
|
|
381
|
+
|
|
382
|
+
if (dataLength === 5) {
|
|
383
|
+
readValue = parser.readUInt32LE;
|
|
384
|
+
} else if (dataLength === 9) {
|
|
385
|
+
readValue = parser.readUNumeric64LE;
|
|
386
|
+
} else if (dataLength === 13) {
|
|
387
|
+
readValue = parser.readUNumeric96LE;
|
|
388
|
+
} else if (dataLength === 17) {
|
|
389
|
+
readValue = parser.readUNumeric128LE;
|
|
390
|
+
} else {
|
|
391
|
+
return parser.emit('error', new Error((0, _sprintfJs.sprintf)('Unsupported numeric dataLength %d', dataLength)));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
readValue.call(parser, value => {
|
|
395
|
+
callback(value * sign / Math.pow(10, scale));
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function readVariant(parser, options, dataLength, callback) {
|
|
401
|
+
return parser.readUInt8(baseType => {
|
|
402
|
+
const type = _dataType.TYPE[baseType];
|
|
403
|
+
return parser.readUInt8(propBytes => {
|
|
404
|
+
dataLength = dataLength - propBytes - 2;
|
|
405
|
+
|
|
406
|
+
switch (type.name) {
|
|
407
|
+
case 'UniqueIdentifier':
|
|
408
|
+
return readUniqueIdentifier(parser, options, callback);
|
|
409
|
+
|
|
410
|
+
case 'Bit':
|
|
411
|
+
return readBit(parser, callback);
|
|
412
|
+
|
|
413
|
+
case 'TinyInt':
|
|
414
|
+
return readTinyInt(parser, callback);
|
|
415
|
+
|
|
416
|
+
case 'SmallInt':
|
|
417
|
+
return readSmallInt(parser, callback);
|
|
418
|
+
|
|
419
|
+
case 'Int':
|
|
420
|
+
return readInt(parser, callback);
|
|
421
|
+
|
|
422
|
+
case 'BigInt':
|
|
423
|
+
return readBigInt(parser, callback);
|
|
249
424
|
|
|
250
425
|
case 'SmallDateTime':
|
|
251
426
|
return readSmallDateTime(parser, options.useUTC, callback);
|
|
@@ -253,174 +428,91 @@ function valueParse(parser, metaData, options, callback) {
|
|
|
253
428
|
case 'DateTime':
|
|
254
429
|
return readDateTime(parser, options.useUTC, callback);
|
|
255
430
|
|
|
256
|
-
case '
|
|
257
|
-
|
|
258
|
-
case 0:
|
|
259
|
-
return callback(null);
|
|
260
|
-
|
|
261
|
-
case 4:
|
|
262
|
-
return readSmallDateTime(parser, options.useUTC, callback);
|
|
431
|
+
case 'Real':
|
|
432
|
+
return readReal(parser, callback);
|
|
263
433
|
|
|
264
|
-
|
|
265
|
-
|
|
434
|
+
case 'Float':
|
|
435
|
+
return readFloat(parser, callback);
|
|
266
436
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
437
|
+
case 'SmallMoney':
|
|
438
|
+
return readSmallMoney(parser, callback);
|
|
270
439
|
|
|
271
|
-
case '
|
|
272
|
-
|
|
273
|
-
return callback(null);
|
|
274
|
-
} else {
|
|
275
|
-
return readTime(parser, dataLength, metaData.scale, options.useUTC, callback);
|
|
276
|
-
}
|
|
440
|
+
case 'Money':
|
|
441
|
+
return readMoney(parser, callback);
|
|
277
442
|
|
|
278
443
|
case 'Date':
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
444
|
+
return readDate(parser, options.useUTC, callback);
|
|
445
|
+
|
|
446
|
+
case 'Time':
|
|
447
|
+
return parser.readUInt8(scale => {
|
|
448
|
+
return readTime(parser, dataLength, scale, options.useUTC, callback);
|
|
449
|
+
});
|
|
284
450
|
|
|
285
451
|
case 'DateTime2':
|
|
286
|
-
|
|
287
|
-
return callback
|
|
288
|
-
}
|
|
289
|
-
return readDateTime2(parser, dataLength, metaData.scale, options.useUTC, callback);
|
|
290
|
-
}
|
|
452
|
+
return parser.readUInt8(scale => {
|
|
453
|
+
return readDateTime2(parser, dataLength, scale, options.useUTC, callback);
|
|
454
|
+
});
|
|
291
455
|
|
|
292
456
|
case 'DateTimeOffset':
|
|
293
|
-
|
|
294
|
-
return callback
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
457
|
+
return parser.readUInt8(scale => {
|
|
458
|
+
return readDateTimeOffset(parser, dataLength, scale, callback);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
case 'VarBinary':
|
|
462
|
+
case 'Binary':
|
|
463
|
+
return parser.readUInt16LE(_maxLength => {
|
|
464
|
+
readBinary(parser, dataLength, callback);
|
|
465
|
+
});
|
|
298
466
|
|
|
299
467
|
case 'NumericN':
|
|
300
468
|
case 'DecimalN':
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
return parser.readUInt8(sign => {
|
|
305
|
-
sign = sign === 1 ? 1 : -1;
|
|
306
|
-
let readValue;
|
|
307
|
-
|
|
308
|
-
switch (dataLength - 1) {
|
|
309
|
-
case 4:
|
|
310
|
-
readValue = parser.readUInt32LE;
|
|
311
|
-
break;
|
|
312
|
-
|
|
313
|
-
case 8:
|
|
314
|
-
readValue = parser.readUNumeric64LE;
|
|
315
|
-
break;
|
|
316
|
-
|
|
317
|
-
case 12:
|
|
318
|
-
readValue = parser.readUNumeric96LE;
|
|
319
|
-
break;
|
|
320
|
-
|
|
321
|
-
case 16:
|
|
322
|
-
readValue = parser.readUNumeric128LE;
|
|
323
|
-
break;
|
|
324
|
-
|
|
325
|
-
default:
|
|
326
|
-
return parser.emit('error', new Error(sprintf('Unsupported numeric size %d', dataLength - 1)));
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
readValue.call(parser, value => {
|
|
330
|
-
callback(value * sign / Math.pow(10, metaData.scale));
|
|
331
|
-
});
|
|
469
|
+
return parser.readUInt8(precision => {
|
|
470
|
+
parser.readUInt8(scale => {
|
|
471
|
+
readNumeric(parser, dataLength, precision, scale, callback);
|
|
332
472
|
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
case 'UniqueIdentifier':
|
|
336
|
-
switch (dataLength) {
|
|
337
|
-
case 0:
|
|
338
|
-
return callback(null);
|
|
339
|
-
|
|
340
|
-
case 0x10:
|
|
341
|
-
return parser.readBuffer(0x10, data => {
|
|
342
|
-
callback(options.lowerCaseGuids ? guidParser.arrayToLowerCaseGuid(data) : guidParser.arrayToUpperCaseGuid(data));
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
default:
|
|
346
|
-
return parser.emit('error', new Error(sprintf('Unsupported guid size %d', dataLength - 1)));
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
case 'UDT':
|
|
350
|
-
return readMaxBinary(parser, callback);
|
|
351
|
-
|
|
352
|
-
case 'Variant':
|
|
353
|
-
if (dataLength === 0) {
|
|
354
|
-
return callback(null);
|
|
355
|
-
}
|
|
473
|
+
});
|
|
356
474
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
475
|
+
case 'VarChar':
|
|
476
|
+
case 'Char':
|
|
477
|
+
return parser.readUInt16LE(_maxLength => {
|
|
478
|
+
(0, _metadataParser.readCollation)(parser, collation => {
|
|
479
|
+
readChars(parser, dataLength, collation.codepage, callback);
|
|
480
|
+
});
|
|
360
481
|
});
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
return readScale(parser, valueMetaData.type, scale => {
|
|
368
|
-
valueMetaData.scale = scale;
|
|
369
|
-
return readCollation(parser, valueMetaData.type, collation => {
|
|
370
|
-
valueMetaData.collation = collation;
|
|
371
|
-
|
|
372
|
-
if (baseType === 0xA5 || baseType === 0xAD || baseType === 0xA7 || baseType === 0xAF || baseType === 0xE7 || baseType === 0xEF) {
|
|
373
|
-
return readDataLength(parser, valueMetaData.type, {}, null, maxDataLength => {
|
|
374
|
-
// skip the 2-byte max length sent for BIGVARCHRTYPE, BIGCHARTYPE, NVARCHARTYPE, NCHARTYPE, BIGVARBINTYPE and BIGBINARYTYPE types
|
|
375
|
-
// and parse based on the length of actual data
|
|
376
|
-
return valueParse(parser, valueMetaData, options, callback);
|
|
377
|
-
});
|
|
378
|
-
} else {
|
|
379
|
-
return valueParse(parser, valueMetaData, options, callback);
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
});
|
|
383
|
-
});
|
|
482
|
+
|
|
483
|
+
case 'NVarChar':
|
|
484
|
+
case 'NChar':
|
|
485
|
+
return parser.readUInt16LE(_maxLength => {
|
|
486
|
+
(0, _metadataParser.readCollation)(parser, _collation => {
|
|
487
|
+
readNChars(parser, dataLength, callback);
|
|
384
488
|
});
|
|
385
489
|
});
|
|
386
490
|
|
|
387
491
|
default:
|
|
388
|
-
|
|
492
|
+
throw new Error('Invalid type!');
|
|
389
493
|
}
|
|
390
494
|
});
|
|
391
495
|
});
|
|
392
496
|
}
|
|
393
497
|
|
|
394
|
-
function readBinary(parser, dataLength,
|
|
395
|
-
|
|
396
|
-
return callback(null);
|
|
397
|
-
} else {
|
|
398
|
-
return parser.readBuffer(dataLength, callback);
|
|
399
|
-
}
|
|
498
|
+
function readBinary(parser, dataLength, callback) {
|
|
499
|
+
return parser.readBuffer(dataLength, callback);
|
|
400
500
|
}
|
|
401
501
|
|
|
402
|
-
function readChars(parser, dataLength, codepage,
|
|
502
|
+
function readChars(parser, dataLength, codepage, callback) {
|
|
403
503
|
if (codepage == null) {
|
|
404
504
|
codepage = DEFAULT_ENCODING;
|
|
405
505
|
}
|
|
406
506
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
return parser.readBuffer(dataLength, data => {
|
|
411
|
-
callback(iconv.decode(data, codepage));
|
|
412
|
-
});
|
|
413
|
-
}
|
|
507
|
+
return parser.readBuffer(dataLength, data => {
|
|
508
|
+
callback(_iconvLite.default.decode(data, codepage));
|
|
509
|
+
});
|
|
414
510
|
}
|
|
415
511
|
|
|
416
|
-
function readNChars(parser, dataLength,
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
return parser.readBuffer(dataLength, data => {
|
|
421
|
-
callback(data.toString('ucs2'));
|
|
422
|
-
});
|
|
423
|
-
}
|
|
512
|
+
function readNChars(parser, dataLength, callback) {
|
|
513
|
+
parser.readBuffer(dataLength, data => {
|
|
514
|
+
callback(data.toString('ucs2'));
|
|
515
|
+
});
|
|
424
516
|
}
|
|
425
517
|
|
|
426
518
|
function readMaxBinary(parser, callback) {
|
|
@@ -434,7 +526,7 @@ function readMaxChars(parser, codepage, callback) {
|
|
|
434
526
|
|
|
435
527
|
readMax(parser, data => {
|
|
436
528
|
if (data) {
|
|
437
|
-
callback(
|
|
529
|
+
callback(_iconvLite.default.decode(data, codepage));
|
|
438
530
|
} else {
|
|
439
531
|
callback(null);
|
|
440
532
|
}
|
|
@@ -605,6 +697,7 @@ function readDate(parser, useUTC, callback) {
|
|
|
605
697
|
|
|
606
698
|
function readDateTime2(parser, dataLength, scale, useUTC, callback) {
|
|
607
699
|
readTime(parser, dataLength - 3, scale, useUTC, time => {
|
|
700
|
+
// TODO: 'input' is 'time', but TypeScript cannot find "time.nanosecondsDelta";
|
|
608
701
|
parser.readUInt24LE(days => {
|
|
609
702
|
let date;
|
|
610
703
|
|
|
@@ -637,4 +730,8 @@ function readDateTimeOffset(parser, dataLength, scale, callback) {
|
|
|
637
730
|
});
|
|
638
731
|
});
|
|
639
732
|
});
|
|
640
|
-
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
var _default = valueParse;
|
|
736
|
+
exports.default = _default;
|
|
737
|
+
module.exports = valueParse;
|