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
package/lib/packet.js CHANGED
@@ -1,13 +1,16 @@
1
- // Generated by CoffeeScript 1.10.0
2
- var DEFAULT_PACKETID, DEFAULT_SPID, DEFAULT_WINDOW, HEADER_LENGTH, NL, OFFSET, Packet, STATUS, TYPE, isPacketComplete, name, packetLength, sprintf, typeByValue, value;
1
+ 'use strict';
2
+
3
+ var _createClass = require('babel-runtime/helpers/create-class')['default'];
4
+
5
+ var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
3
6
 
4
7
  require('./buffertools');
5
8
 
6
- sprintf = require('sprintf').sprintf;
9
+ var sprintf = require('sprintf').sprintf;
7
10
 
8
- HEADER_LENGTH = 8;
11
+ var HEADER_LENGTH = module.exports.HEADER_LENGTH = 8;
9
12
 
10
- TYPE = {
13
+ var TYPE = module.exports.TYPE = {
11
14
  SQL_BATCH: 0x01,
12
15
  RPC_REQUEST: 0x03,
13
16
  TABULAR_RESULT: 0x04,
@@ -19,14 +22,13 @@ TYPE = {
19
22
  PRELOGIN: 0x12
20
23
  };
21
24
 
22
- typeByValue = {};
25
+ var typeByValue = {};
23
26
 
24
- for (name in TYPE) {
25
- value = TYPE[name];
26
- typeByValue[value] = name;
27
+ for (var _name in TYPE) {
28
+ typeByValue[TYPE[_name]] = _name;
27
29
  }
28
30
 
29
- STATUS = {
31
+ var STATUS = {
30
32
  NORMAL: 0x00,
31
33
  EOM: 0x01,
32
34
  IGNORE: 0x02,
@@ -34,7 +36,7 @@ STATUS = {
34
36
  RESETCONNECTIONSKIPTRAN: 0x10
35
37
  };
36
38
 
37
- OFFSET = {
39
+ var OFFSET = module.exports.OFFSET = {
38
40
  Type: 0,
39
41
  Status: 1,
40
42
  Length: 2,
@@ -43,21 +45,22 @@ OFFSET = {
43
45
  Window: 7
44
46
  };
45
47
 
46
- DEFAULT_SPID = 0;
48
+ var DEFAULT_SPID = 0;
47
49
 
48
- DEFAULT_PACKETID = 1;
50
+ var DEFAULT_PACKETID = 1;
49
51
 
50
- DEFAULT_WINDOW = 0;
52
+ var DEFAULT_WINDOW = 0;
51
53
 
52
- NL = '\n';
54
+ var NL = '\n';
53
55
 
54
- Packet = (function () {
56
+ var Packet = (function () {
55
57
  function Packet(typeOrBuffer) {
56
- var type;
58
+ _classCallCheck(this, Packet);
59
+
57
60
  if (typeOrBuffer instanceof Buffer) {
58
61
  this.buffer = typeOrBuffer;
59
62
  } else {
60
- type = typeOrBuffer;
63
+ var type = typeOrBuffer;
61
64
  this.buffer = new Buffer(HEADER_LENGTH);
62
65
  this.buffer.writeUInt8(type, OFFSET.Type);
63
66
  this.buffer.writeUInt8(STATUS.NORMAL, OFFSET.Status);
@@ -68,164 +71,175 @@ Packet = (function () {
68
71
  }
69
72
  }
70
73
 
71
- Packet.prototype.setLength = function () {
72
- return this.buffer.writeUInt16BE(this.buffer.length, OFFSET.Length);
73
- };
74
-
75
- Packet.prototype.length = function () {
76
- return this.buffer.readUInt16BE(OFFSET.Length);
77
- };
78
-
79
- Packet.prototype.resetConnection = function (reset) {
80
- var status;
81
- status = this.buffer.readUInt8(OFFSET.Status);
82
- if (reset) {
83
- status |= STATUS.RESETCONNECTION;
84
- } else {
85
- status &= 0xFF - STATUS.RESETCONNECTION;
74
+ _createClass(Packet, [{
75
+ key: 'setLength',
76
+ value: function setLength() {
77
+ return this.buffer.writeUInt16BE(this.buffer.length, OFFSET.Length);
78
+ }
79
+ }, {
80
+ key: 'length',
81
+ value: function length() {
82
+ return this.buffer.readUInt16BE(OFFSET.Length);
86
83
  }
87
- return this.buffer.writeUInt8(status, OFFSET.Status);
88
- };
89
-
90
- Packet.prototype.last = function (last) {
91
- var status;
92
- status = this.buffer.readUInt8(OFFSET.Status);
93
- if (arguments.length > 0) {
94
- if (last) {
95
- status |= STATUS.EOM;
84
+ }, {
85
+ key: 'resetConnection',
86
+ value: function resetConnection(reset) {
87
+ var status = this.buffer.readUInt8(OFFSET.Status);
88
+ if (reset) {
89
+ status |= STATUS.RESETCONNECTION;
96
90
  } else {
97
- status &= 0xFF - STATUS.EOM;
91
+ status &= 0xFF - STATUS.RESETCONNECTION;
92
+ }
93
+ return this.buffer.writeUInt8(status, OFFSET.Status);
94
+ }
95
+ }, {
96
+ key: 'last',
97
+ value: function last(_last) {
98
+ var status = this.buffer.readUInt8(OFFSET.Status);
99
+ if (arguments.length > 0) {
100
+ if (_last) {
101
+ status |= STATUS.EOM;
102
+ } else {
103
+ status &= 0xFF - STATUS.EOM;
104
+ }
105
+ this.buffer.writeUInt8(status, OFFSET.Status);
106
+ }
107
+ return this.isLast();
108
+ }
109
+ }, {
110
+ key: 'isLast',
111
+ value: function isLast() {
112
+ return !!(this.buffer.readUInt8(OFFSET.Status) & STATUS.EOM);
113
+ }
114
+ }, {
115
+ key: 'packetId',
116
+ value: function packetId(_packetId) {
117
+ if (_packetId) {
118
+ this.buffer.writeUInt8(_packetId % 256, OFFSET.PacketID);
98
119
  }
99
- this.buffer.writeUInt8(status, OFFSET.Status);
120
+ return this.buffer.readUInt8(OFFSET.PacketID);
121
+ }
122
+ }, {
123
+ key: 'addData',
124
+ value: function addData(data) {
125
+ this.buffer = Buffer.concat([this.buffer, data]);
126
+ this.setLength();
127
+ return this;
128
+ }
129
+ }, {
130
+ key: 'data',
131
+ value: function data() {
132
+ return this.buffer.slice(HEADER_LENGTH);
100
133
  }
101
- return this.isLast();
102
- };
134
+ }, {
135
+ key: 'type',
136
+ value: function type() {
137
+ return this.buffer.readUInt8(OFFSET.Type);
138
+ }
139
+ }, {
140
+ key: 'statusAsString',
141
+ value: function statusAsString() {
142
+ var status = this.buffer.readUInt8(OFFSET.Status);
143
+ var statuses = [];
103
144
 
104
- Packet.prototype.isLast = function () {
105
- return !!(this.buffer.readUInt8(OFFSET.Status) & STATUS.EOM);
106
- };
145
+ for (var _name2 in STATUS) {
146
+ var value = STATUS[_name2];
107
147
 
108
- Packet.prototype.packetId = function (packetId) {
109
- if (packetId) {
110
- this.buffer.writeUInt8(packetId % 256, OFFSET.PacketID);
111
- }
112
- return this.buffer.readUInt8(OFFSET.PacketID);
113
- };
114
-
115
- Packet.prototype.addData = function (data) {
116
- this.buffer = Buffer.concat([this.buffer, data]);
117
- this.setLength();
118
- return this;
119
- };
120
-
121
- Packet.prototype.data = function () {
122
- return this.buffer.slice(HEADER_LENGTH);
123
- };
124
-
125
- Packet.prototype.type = function () {
126
- return this.buffer.readUInt8(OFFSET.Type);
127
- };
128
-
129
- Packet.prototype.statusAsString = function () {
130
- var status, statuses;
131
- status = this.buffer.readUInt8(OFFSET.Status);
132
- statuses = (function () {
133
- var results;
134
- results = [];
135
- for (name in STATUS) {
136
- value = STATUS[name];
137
148
  if (status & value) {
138
- results.push(name);
149
+ statuses.push(_name2);
139
150
  } else {
140
- results.push(void 0);
151
+ statuses.push(undefined);
141
152
  }
142
153
  }
143
- return results;
144
- })();
145
- return statuses.join(' ').trim();
146
- };
147
-
148
- Packet.prototype.headerToString = function (indent) {
149
- var text;
150
- indent || (indent = '');
151
- text = sprintf('type:0x%02X(%s), status:0x%02X(%s), length:0x%04X, spid:0x%04X, packetId:0x%02X, window:0x%02X', this.buffer.readUInt8(OFFSET.Type), typeByValue[this.buffer.readUInt8(OFFSET.Type)], this.buffer.readUInt8(OFFSET.Status), this.statusAsString(), this.buffer.readUInt16BE(OFFSET.Length), this.buffer.readUInt16BE(OFFSET.SPID), this.buffer.readUInt8(OFFSET.PacketID), this.buffer.readUInt8(OFFSET.Window));
152
- return indent + text;
153
- };
154
-
155
- Packet.prototype.dataToString = function (indent) {
156
- var BYTES_PER_GROUP, BYTES_PER_LINE, CHARS_PER_GROUP, chars, data, dataDump, i, offset, ref;
157
- BYTES_PER_GROUP = 0x04;
158
- CHARS_PER_GROUP = 0x08;
159
- BYTES_PER_LINE = 0x20;
160
- indent || (indent = '');
161
- data = this.data();
162
- dataDump = '';
163
- chars = '';
164
- for (offset = i = 0, ref = data.length - 1; 0 <= ref ? i <= ref : i >= ref; offset = 0 <= ref ? ++i : --i) {
165
- if (offset % BYTES_PER_LINE === 0) {
166
- dataDump += indent;
167
- dataDump += sprintf('%04X ', offset);
168
- }
169
- if (data[offset] < 0x20 || data[offset] > 0x7E) {
170
- chars += '.';
171
- if ((offset + 1) % CHARS_PER_GROUP === 0 && !((offset + 1) % BYTES_PER_LINE === 0)) {
172
- chars += ' ';
154
+
155
+ return statuses.join(' ').trim();
156
+ }
157
+ }, {
158
+ key: 'headerToString',
159
+ value: function headerToString(indent) {
160
+ indent || (indent = '');
161
+ var text = sprintf('type:0x%02X(%s), status:0x%02X(%s), length:0x%04X, spid:0x%04X, packetId:0x%02X, window:0x%02X', this.buffer.readUInt8(OFFSET.Type), typeByValue[this.buffer.readUInt8(OFFSET.Type)], this.buffer.readUInt8(OFFSET.Status), this.statusAsString(), this.buffer.readUInt16BE(OFFSET.Length), this.buffer.readUInt16BE(OFFSET.SPID), this.buffer.readUInt8(OFFSET.PacketID), this.buffer.readUInt8(OFFSET.Window));
162
+ return indent + text;
163
+ }
164
+ }, {
165
+ key: 'dataToString',
166
+ value: function dataToString(indent) {
167
+ indent || (indent = '');
168
+
169
+ var BYTES_PER_GROUP = 0x04;
170
+ var CHARS_PER_GROUP = 0x08;
171
+ var BYTES_PER_LINE = 0x20;
172
+ var data = this.data();
173
+
174
+ var dataDump = '';
175
+ var chars = '';
176
+
177
+ for (var offset = 0; offset < data.length; offset++) {
178
+ if (offset % BYTES_PER_LINE === 0) {
179
+ dataDump += indent;
180
+ dataDump += sprintf('%04X ', offset);
181
+ }
182
+
183
+ if (data[offset] < 0x20 || data[offset] > 0x7E) {
184
+ chars += '.';
185
+ if ((offset + 1) % CHARS_PER_GROUP === 0 && !((offset + 1) % BYTES_PER_LINE === 0)) {
186
+ chars += ' ';
187
+ }
188
+ } else {
189
+ chars += String.fromCharCode(data[offset]);
190
+ }
191
+
192
+ if (data[offset] != null) {
193
+ dataDump += sprintf('%02X', data[offset]);
194
+ }
195
+
196
+ if ((offset + 1) % BYTES_PER_GROUP === 0 && !((offset + 1) % BYTES_PER_LINE === 0)) {
197
+ dataDump += ' ';
198
+ }
199
+
200
+ if ((offset + 1) % BYTES_PER_LINE === 0) {
201
+ dataDump += ' ' + chars;
202
+ chars = '';
203
+ if (offset < data.length - 1) {
204
+ dataDump += NL;
205
+ }
173
206
  }
174
- } else {
175
- chars += String.fromCharCode(data[offset]);
176
- }
177
- if (data[offset] != null) {
178
- dataDump += sprintf('%02X', data[offset]);
179
- }
180
- if ((offset + 1) % BYTES_PER_GROUP === 0 && !((offset + 1) % BYTES_PER_LINE === 0)) {
181
- dataDump += ' ';
182
207
  }
183
- if ((offset + 1) % BYTES_PER_LINE === 0) {
208
+
209
+ if (chars.length) {
184
210
  dataDump += ' ' + chars;
185
- chars = '';
186
- if (offset < data.length - 1) {
187
- dataDump += NL;
188
- }
189
211
  }
212
+
213
+ return dataDump;
190
214
  }
191
- if (chars.length) {
192
- dataDump += ' ' + chars;
215
+ }, {
216
+ key: 'toString',
217
+ value: function toString(indent) {
218
+ indent || (indent = '');
219
+ return this.headerToString(indent) + '\n' + this.dataToString(indent + indent);
193
220
  }
194
- return dataDump;
195
- };
196
-
197
- Packet.prototype.toString = function (indent) {
198
- indent || (indent = '');
199
- return this.headerToString(indent) + '\n' + this.dataToString(indent + indent);
200
- };
201
-
202
- Packet.prototype.payloadString = function (indent) {
203
- return "";
204
- };
221
+ }, {
222
+ key: 'payloadString',
223
+ value: function payloadString() {
224
+ return '';
225
+ }
226
+ }]);
205
227
 
206
228
  return Packet;
207
229
  })();
208
230
 
209
- isPacketComplete = function (potentialPacketBuffer) {
231
+ module.exports.Packet = Packet;
232
+
233
+ module.exports.isPacketComplete = isPacketComplete;
234
+ function isPacketComplete(potentialPacketBuffer) {
210
235
  if (potentialPacketBuffer.length < HEADER_LENGTH) {
211
236
  return false;
212
237
  } else {
213
238
  return potentialPacketBuffer.length >= potentialPacketBuffer.readUInt16BE(OFFSET.Length);
214
239
  }
215
- };
240
+ }
216
241
 
217
- packetLength = function (potentialPacketBuffer) {
242
+ module.exports.packetLength = packetLength;
243
+ function packetLength(potentialPacketBuffer) {
218
244
  return potentialPacketBuffer.readUInt16BE(OFFSET.Length);
219
- };
220
-
221
- exports.Packet = Packet;
222
-
223
- exports.OFFSET = OFFSET;
224
-
225
- exports.TYPE = TYPE;
226
-
227
- exports.isPacketComplete = isPacketComplete;
228
-
229
- exports.packetLength = packetLength;
230
-
231
- exports.HEADER_LENGTH = HEADER_LENGTH;
245
+ }