tedious 1.12.3 → 1.14.0

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.
Files changed (62) hide show
  1. package/README.md +1 -1
  2. package/appveyor.yml +9 -5
  3. package/benchmarks/README.md +33 -0
  4. package/benchmarks/common.js +82 -0
  5. package/benchmarks/index.js +34 -0
  6. package/benchmarks/query/many-result-rows.js +49 -0
  7. package/benchmarks/query/nvarchar-large.js +44 -0
  8. package/benchmarks/query/nvarchar-small.js +44 -0
  9. package/benchmarks/query/varbinary-4.js +42 -0
  10. package/benchmarks/query/varbinary-huge.js +46 -0
  11. package/benchmarks/query/varbinary-large.js +46 -0
  12. package/benchmarks/query/varbinary-small.js +42 -0
  13. package/benchmarks/token-parser/colmetadata-token.js +42 -0
  14. package/benchmarks/token-parser/done-token.js +42 -0
  15. package/benchmarks/token-parser/simple-tokens.js +366 -0
  16. package/lib/all-headers.js +9 -11
  17. package/lib/buffertools.js +17 -13
  18. package/lib/bulk-load.js +196 -169
  19. package/lib/collation.js +80 -2
  20. package/lib/connection.js +1086 -1060
  21. package/lib/data-type.js +450 -253
  22. package/lib/debug.js +57 -51
  23. package/lib/errors.js +40 -55
  24. package/lib/guid-parser.js +12 -36
  25. package/lib/instance-lookup.js +57 -54
  26. package/lib/library.js +3 -2
  27. package/lib/login7-payload.js +187 -180
  28. package/lib/message-io.js +169 -199
  29. package/lib/metadata-parser.js +169 -255
  30. package/lib/ntlm-payload.js +173 -160
  31. package/lib/packet.js +166 -152
  32. package/lib/prelogin-payload.js +170 -160
  33. package/lib/request.js +122 -122
  34. package/lib/rpcrequest-payload.js +64 -38
  35. package/lib/special-stored-procedure.js +3 -2
  36. package/lib/sqlbatch-payload.js +20 -16
  37. package/lib/stream-parser.js +116 -104
  38. package/lib/tds-versions.js +5 -8
  39. package/lib/tedious.js +8 -14
  40. package/lib/token/colmetadata-token-parser.js +79 -125
  41. package/lib/token/done-token-parser.js +47 -129
  42. package/lib/token/env-change-token-parser.js +90 -126
  43. package/lib/token/infoerror-token-parser.js +47 -125
  44. package/lib/token/loginack-token-parser.js +36 -74
  45. package/lib/token/nbcrow-token-parser.js +40 -64
  46. package/lib/token/order-token-parser.js +26 -43
  47. package/lib/token/returnstatus-token-parser.js +11 -23
  48. package/lib/token/returnvalue-token-parser.js +31 -54
  49. package/lib/token/row-token-parser.js +39 -52
  50. package/lib/token/sspi-token-parser.js +14 -32
  51. package/lib/token/stream-parser.js +424 -304
  52. package/lib/token/token-stream-parser.js +39 -34
  53. package/lib/token/token.js +3 -6
  54. package/lib/tracking-buffer/bigint.js +45 -48
  55. package/lib/tracking-buffer/readable-tracking-buffer.js +238 -223
  56. package/lib/tracking-buffer/tracking-buffer.js +3 -9
  57. package/lib/tracking-buffer/writable-tracking-buffer.js +272 -244
  58. package/lib/transaction.js +112 -102
  59. package/lib/value-parser.js +559 -1154
  60. package/package.json +10 -9
  61. package/benchmarks/benchmarks.coffee +0 -122
  62. package/benchmarks/query.coffee +0 -57
@@ -1,263 +1,177 @@
1
- var _regeneratorRuntime = require('babel-runtime/regenerator').default;
2
-
3
- // Generated by CoffeeScript 1.10.0
4
- var TYPE, codepageByLcid, sprintf;
5
-
6
- codepageByLcid = require('./collation').codepageByLcid;
7
-
8
- TYPE = require('./data-type').TYPE;
9
-
10
- sprintf = require('sprintf').sprintf;
11
-
12
- module.exports = _regeneratorRuntime.mark(function callee$0$0(parser, options) {
13
- var collation, collationData, dataLength, flags, metadata, precision, scale, schema, schemaPresent, type, typeNumber, udtInfo, userType;
14
- return _regeneratorRuntime.wrap(function callee$0$0$(context$1$0) {
15
- while (1) switch (context$1$0.prev = context$1$0.next) {
1
+ 'use strict';
2
+
3
+ var codepageBySortId = require('./collation').codepageBySortId;
4
+ var codepageByLcid = require('./collation').codepageByLcid;
5
+ var TYPE = require('./data-type').TYPE;
6
+ var sprintf = require('sprintf').sprintf;
7
+
8
+ module.exports = metadataParse;
9
+ module.exports.readPrecision = readPrecision;
10
+ module.exports.readScale = readScale;
11
+ module.exports.readCollation = readCollation;
12
+
13
+ function readDataLength(parser, type, callback) {
14
+ if ((type.id & 0x30) === 0x20) {
15
+ // xx10xxxx - s2.2.4.2.1.3
16
+ // Variable length
17
+ if (type.dataLengthFromScale) {
18
+ return callback(0); // dataLength is resolved from scale
19
+ } else if (type.fixedDataLength) {
20
+ return callback(type.fixedDataLength);
21
+ }
22
+
23
+ switch (type.dataLengthLength) {
16
24
  case 0:
17
- if (!(options.tdsVersion < "7_2")) {
18
- context$1$0.next = 6;
19
- break;
20
- }
21
-
22
- context$1$0.next = 3;
23
- return parser.readUInt16LE();
24
-
25
- case 3:
26
- userType = context$1$0.sent;
27
- context$1$0.next = 9;
28
- break;
29
-
30
- case 6:
31
- context$1$0.next = 8;
32
- return parser.readUInt32LE();
33
-
34
- case 8:
35
- userType = context$1$0.sent;
36
-
37
- case 9:
38
- context$1$0.next = 11;
39
- return parser.readUInt16LE();
40
-
41
- case 11:
42
- flags = context$1$0.sent;
43
- context$1$0.next = 14;
44
- return parser.readUInt8();
45
-
46
- case 14:
47
- typeNumber = context$1$0.sent;
48
-
49
- type = TYPE[typeNumber];
50
-
51
- if (type) {
52
- context$1$0.next = 18;
53
- break;
54
- }
55
-
56
- throw new Error(sprintf('Unrecognised data type 0x%02X', typeNumber));
57
-
58
- case 18:
59
- if (!((type.id & 0x30) === 0x20)) {
60
- context$1$0.next = 39;
61
- break;
62
- }
63
-
64
- context$1$0.t0 = type.dataLengthLength;
65
- context$1$0.next = context$1$0.t0 === 0 ? 22 : context$1$0.t0 === 1 ? 24 : context$1$0.t0 === 2 ? 28 : context$1$0.t0 === 4 ? 32 : 36;
66
- break;
67
-
68
- case 22:
69
- dataLength = void 0;
70
- return context$1$0.abrupt('break', 37);
71
-
72
- case 24:
73
- context$1$0.next = 26;
74
- return parser.readUInt8();
75
-
76
- case 26:
77
- dataLength = context$1$0.sent;
78
- return context$1$0.abrupt('break', 37);
79
-
80
- case 28:
81
- context$1$0.next = 30;
82
- return parser.readUInt16LE();
83
-
84
- case 30:
85
- dataLength = context$1$0.sent;
86
- return context$1$0.abrupt('break', 37);
87
-
88
- case 32:
89
- context$1$0.next = 34;
90
- return parser.readUInt32LE();
91
-
92
- case 34:
93
- dataLength = context$1$0.sent;
94
- return context$1$0.abrupt('break', 37);
95
-
96
- case 36:
97
- throw new Error("Unsupported dataLengthLength " + type.dataLengthLength + " for data type " + type.name);
98
-
99
- case 37:
100
- context$1$0.next = 40;
101
- break;
102
-
103
- case 39:
104
- dataLength = void 0;
105
-
106
- case 40:
107
- if (!type.hasPrecision) {
108
- context$1$0.next = 46;
109
- break;
110
- }
111
-
112
- context$1$0.next = 43;
113
- return parser.readUInt8();
114
-
115
- case 43:
116
- precision = context$1$0.sent;
117
- context$1$0.next = 47;
118
- break;
25
+ return callback(undefined);
119
26
 
120
- case 46:
121
- precision = void 0;
27
+ case 1:
28
+ return parser.readUInt8(callback);
122
29
 
123
- case 47:
124
- if (!type.hasScale) {
125
- context$1$0.next = 54;
126
- break;
127
- }
128
-
129
- context$1$0.next = 50;
130
- return parser.readUInt8();
131
-
132
- case 50:
133
- scale = context$1$0.sent;
134
-
135
- if (type.dataLengthFromScale) {
136
- dataLength = type.dataLengthFromScale(scale);
137
- }
138
- context$1$0.next = 55;
139
- break;
140
-
141
- case 54:
142
- scale = void 0;
143
-
144
- case 55:
145
- if (!type.hasCollation) {
146
- context$1$0.next = 70;
147
- break;
148
- }
149
-
150
- context$1$0.next = 58;
151
- return parser.readBuffer(5);
152
-
153
- case 58:
154
- collationData = context$1$0.sent;
155
-
156
- collation = {};
157
- collation.lcid = (collationData[2] & 0x0F) << 16;
158
- collation.lcid |= collationData[1] << 8;
159
- collation.lcid |= collationData[0];
160
- collation.codepage = codepageByLcid[collation.lcid];
161
- collation.flags = collationData[3] >> 4;
162
- collation.flags |= collationData[2] & 0xF0;
163
- collation.version = collationData[3] & 0x0F;
164
- collation.sortId = collationData[4];
165
- context$1$0.next = 71;
166
- break;
167
-
168
- case 70:
169
- collation = void 0;
170
-
171
- case 71:
172
- schema = void 0;
173
-
174
- if (!type.hasSchemaPresent) {
175
- context$1$0.next = 84;
176
- break;
177
- }
178
-
179
- context$1$0.next = 75;
180
- return parser.readUInt8();
181
-
182
- case 75:
183
- schemaPresent = context$1$0.sent;
30
+ case 2:
31
+ return parser.readUInt16LE(callback);
184
32
 
185
- if (!(schemaPresent === 0x01)) {
186
- context$1$0.next = 84;
187
- break;
188
- }
189
-
190
- return context$1$0.delegateYield(parser.readBVarChar(), 't1', 78);
191
-
192
- case 78:
193
- context$1$0.t2 = context$1$0.t1;
194
- return context$1$0.delegateYield(parser.readBVarChar(), 't3', 80);
195
-
196
- case 80:
197
- context$1$0.t4 = context$1$0.t3;
198
- return context$1$0.delegateYield(parser.readUsVarChar(), 't5', 82);
199
-
200
- case 82:
201
- context$1$0.t6 = context$1$0.t5;
202
- schema = {
203
- dbname: context$1$0.t2,
204
- owningSchema: context$1$0.t4,
205
- xmlSchemaCollection: context$1$0.t6
206
- };
33
+ case 4:
34
+ return parser.readUInt32LE(callback);
207
35
 
208
- case 84:
209
- udtInfo = void 0;
210
-
211
- if (!type.hasUDTInfo) {
212
- context$1$0.next = 98;
213
- break;
36
+ default:
37
+ return parser.emit(new Error('Unsupported dataLengthLength ' + type.dataLengthLength + ' for data type ' + type.name));
38
+ }
39
+ } else {
40
+ callback(undefined);
41
+ }
42
+ }
43
+
44
+ function readPrecision(parser, type, callback) {
45
+ if (type.hasPrecision) {
46
+ parser.readUInt8(callback);
47
+ } else {
48
+ callback(undefined);
49
+ }
50
+ }
51
+
52
+ function readScale(parser, type, callback) {
53
+ if (type.hasScale) {
54
+ parser.readUInt8(callback);
55
+ } else {
56
+ callback(undefined);
57
+ }
58
+ }
59
+
60
+ function readCollation(parser, type, callback) {
61
+ if (type.hasCollation) {
62
+ // s2.2.5.1.2
63
+ parser.readBuffer(5, function (collationData) {
64
+ var collation = {};
65
+
66
+ collation.lcid = (collationData[2] & 0x0F) << 16;
67
+ collation.lcid |= collationData[1] << 8;
68
+ collation.lcid |= collationData[0];
69
+
70
+ // This may not be extracting the correct nibbles in the correct order.
71
+ collation.flags = collationData[3] >> 4;
72
+ collation.flags |= collationData[2] & 0xF0;
73
+
74
+ // This may not be extracting the correct nibble.
75
+ collation.version = collationData[3] & 0x0F;
76
+
77
+ collation.sortId = collationData[4];
78
+
79
+ collation.codepage = codepageBySortId[collation.sortId] || codepageByLcid[collation.lcid] || 'CP1252';
80
+
81
+ callback(collation);
82
+ });
83
+ } else {
84
+ callback(undefined);
85
+ }
86
+ }
87
+
88
+ function readSchema(parser, type, callback) {
89
+ if (type.hasSchemaPresent) {
90
+ // s2.2.5.5.3
91
+ parser.readUInt8(function (schemaPresent) {
92
+ if (schemaPresent === 0x01) {
93
+ parser.readBVarChar(function (dbname) {
94
+ parser.readBVarChar(function (owningSchema) {
95
+ parser.readUsVarChar(function (xmlSchemaCollection) {
96
+ callback({
97
+ dbname: dbname,
98
+ owningSchema: owningSchema,
99
+ xmlSchemaCollection: xmlSchemaCollection
100
+ });
101
+ });
102
+ });
103
+ });
104
+ } else {
105
+ callback(undefined);
106
+ }
107
+ });
108
+ } else {
109
+ callback(undefined);
110
+ }
111
+ }
112
+
113
+ function readUDTInfo(parser, type, callback) {
114
+ if (type.hasUDTInfo) {
115
+ parser.readUInt16LE(function (maxByteSize) {
116
+ parser.readBVarChar(function (dbname) {
117
+ parser.readBVarChar(function (owningSchema) {
118
+ parser.readBVarChar(function (typeName) {
119
+ parser.readUsVarChar(function (assemblyName) {
120
+ callback({
121
+ maxByteSize: maxByteSize,
122
+ dbname: dbname,
123
+ owningSchema: owningSchema,
124
+ typeName: typeName,
125
+ assemblyName: assemblyName
126
+ });
127
+ });
128
+ });
129
+ });
130
+ });
131
+ });
132
+ } else {
133
+ return callback();
134
+ }
135
+ }
136
+
137
+ function metadataParse(parser, options, callback) {
138
+ (options.tdsVersion < '7_2' ? parser.readUInt16LE : parser.readUInt32LE).call(parser, function (userType) {
139
+ parser.readUInt16LE(function (flags) {
140
+ parser.readUInt8(function (typeNumber) {
141
+ var type = TYPE[typeNumber];
142
+
143
+ if (!type) {
144
+ return parser.emit(new Error(sprintf('Unrecognised data type 0x%02X', typeNumber)));
214
145
  }
215
146
 
216
- context$1$0.next = 88;
217
- return parser.readUInt16LE();
218
-
219
- case 88:
220
- context$1$0.t7 = context$1$0.sent;
221
- return context$1$0.delegateYield(parser.readBVarChar(), 't8', 90);
222
-
223
- case 90:
224
- context$1$0.t9 = context$1$0.t8;
225
- return context$1$0.delegateYield(parser.readBVarChar(), 't10', 92);
226
-
227
- case 92:
228
- context$1$0.t11 = context$1$0.t10;
229
- return context$1$0.delegateYield(parser.readBVarChar(), 't12', 94);
230
-
231
- case 94:
232
- context$1$0.t13 = context$1$0.t12;
233
- return context$1$0.delegateYield(parser.readUsVarChar(), 't14', 96);
234
-
235
- case 96:
236
- context$1$0.t15 = context$1$0.t14;
237
- udtInfo = {
238
- maxByteSize: context$1$0.t7,
239
- dbname: context$1$0.t9,
240
- owningSchema: context$1$0.t11,
241
- typeName: context$1$0.t13,
242
- assemblyName: context$1$0.t15
243
- };
244
-
245
- case 98:
246
- return context$1$0.abrupt('return', metadata = {
247
- userType: userType,
248
- flags: flags,
249
- type: type,
250
- collation: collation,
251
- precision: precision,
252
- scale: scale,
253
- dataLength: dataLength,
254
- schema: schema,
255
- udtInfo: udtInfo
147
+ readDataLength(parser, type, function (dataLength) {
148
+ readPrecision(parser, type, function (precision) {
149
+ readScale(parser, type, function (scale) {
150
+ if (scale && type.dataLengthFromScale) {
151
+ dataLength = type.dataLengthFromScale(scale);
152
+ }
153
+
154
+ readCollation(parser, type, function (collation) {
155
+ readSchema(parser, type, function (schema) {
156
+ readUDTInfo(parser, type, function (udtInfo) {
157
+ callback({
158
+ userType: userType,
159
+ flags: flags,
160
+ type: type,
161
+ collation: collation,
162
+ precision: precision,
163
+ scale: scale,
164
+ dataLength: dataLength,
165
+ schema: schema,
166
+ udtInfo: udtInfo
167
+ });
168
+ });
169
+ });
170
+ });
171
+ });
172
+ });
256
173
  });
257
-
258
- case 99:
259
- case 'end':
260
- return context$1$0.stop();
261
- }
262
- }, callee$0$0, this);
263
- });
174
+ });
175
+ });
176
+ });
177
+ }