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/debug.js CHANGED
@@ -1,30 +1,30 @@
1
- // Generated by CoffeeScript 1.10.0
2
- var Debug,
3
- EventEmitter,
4
- util,
5
- extend = function (child, parent) {
6
- for (var key in parent) {
7
- if (hasProp.call(parent, key)) child[key] = parent[key];
8
- }function ctor() {
9
- this.constructor = child;
10
- }ctor.prototype = parent.prototype;child.prototype = new ctor();child.__super__ = parent.prototype;return child;
11
- },
12
- hasProp = ({}).hasOwnProperty;
1
+ 'use strict';
13
2
 
14
- EventEmitter = require('events').EventEmitter;
3
+ var _get = require('babel-runtime/helpers/get')['default'];
15
4
 
16
- util = require('util');
5
+ var _inherits = require('babel-runtime/helpers/inherits')['default'];
17
6
 
18
- Debug = (function (superClass) {
19
- extend(Debug, superClass);
7
+ var _createClass = require('babel-runtime/helpers/create-class')['default'];
8
+
9
+ var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
10
+
11
+ var EventEmitter = require('events').EventEmitter;
12
+ var util = require('util');
13
+
14
+ module.exports = (function (_EventEmitter) {
15
+ _inherits(Debug, _EventEmitter);
20
16
 
21
17
  /*
22
18
  @options Which debug details should be sent.
23
- data - dump of packet data
24
- payload - details of decoded payload
25
- */
19
+ data - dump of packet data
20
+ payload - details of decoded payload
21
+ */
26
22
 
27
23
  function Debug(options) {
24
+ _classCallCheck(this, Debug);
25
+
26
+ _get(Object.getPrototypeOf(Debug.prototype), 'constructor', this).call(this);
27
+
28
28
  this.options = options;
29
29
  this.options = this.options || {};
30
30
  this.options.data = this.options.data || false;
@@ -34,41 +34,47 @@ Debug = (function (superClass) {
34
34
  this.indent = ' ';
35
35
  }
36
36
 
37
- Debug.prototype.packet = function (direction, packet) {
38
- if (this.haveListeners() && this.options.packet) {
39
- this.log('');
40
- this.log(direction);
41
- return this.log(packet.headerToString(this.indent));
37
+ _createClass(Debug, [{
38
+ key: 'packet',
39
+ value: function packet(direction, _packet) {
40
+ if (this.haveListeners() && this.options.packet) {
41
+ this.log('');
42
+ this.log(direction);
43
+ this.log(_packet.headerToString(this.indent));
44
+ }
42
45
  }
43
- };
44
-
45
- Debug.prototype.data = function (packet) {
46
- if (this.haveListeners() && this.options.data) {
47
- return this.log(packet.dataToString(this.indent));
46
+ }, {
47
+ key: 'data',
48
+ value: function data(packet) {
49
+ if (this.haveListeners() && this.options.data) {
50
+ this.log(packet.dataToString(this.indent));
51
+ }
48
52
  }
49
- };
50
-
51
- Debug.prototype.payload = function (generatePayloadText) {
52
- if (this.haveListeners() && this.options.payload) {
53
- return this.log(generatePayloadText());
53
+ }, {
54
+ key: 'payload',
55
+ value: function payload(generatePayloadText) {
56
+ if (this.haveListeners() && this.options.payload) {
57
+ this.log(generatePayloadText());
58
+ }
54
59
  }
55
- };
56
-
57
- Debug.prototype.token = function (token) {
58
- if (this.haveListeners() && this.options.token) {
59
- return this.log(util.inspect(token, false, 5, true));
60
+ }, {
61
+ key: 'token',
62
+ value: function token(_token) {
63
+ if (this.haveListeners() && this.options.token) {
64
+ this.log(util.inspect(_token, false, 5, true));
65
+ }
60
66
  }
61
- };
62
-
63
- Debug.prototype.haveListeners = function () {
64
- return this.listeners('debug').length > 0;
65
- };
66
-
67
- Debug.prototype.log = function (text) {
68
- return this.emit('debug', text);
69
- };
67
+ }, {
68
+ key: 'haveListeners',
69
+ value: function haveListeners() {
70
+ return this.listeners('debug').length > 0;
71
+ }
72
+ }, {
73
+ key: 'log',
74
+ value: function log(text) {
75
+ this.emit('debug', text);
76
+ }
77
+ }]);
70
78
 
71
79
  return Debug;
72
- })(EventEmitter);
73
-
74
- module.exports = Debug;
80
+ })(EventEmitter);
package/lib/errors.js CHANGED
@@ -1,62 +1,47 @@
1
- // Generated by CoffeeScript 1.10.0
2
- var ConnectionError,
3
- RequestError,
4
- extend = function (child, parent) {
5
- for (var key in parent) {
6
- if (hasProp.call(parent, key)) child[key] = parent[key];
7
- }function ctor() {
8
- this.constructor = child;
9
- }ctor.prototype = parent.prototype;child.prototype = new ctor();child.__super__ = parent.prototype;return child;
10
- },
11
- hasProp = ({}).hasOwnProperty;
12
-
13
- ConnectionError = (function (superClass) {
14
- extend(ConnectionError, superClass);
15
-
16
- function ConnectionError(message, code) {
17
- var err;
18
- if (!(this instanceof ConnectionError)) {
19
- if (message instanceof ConnectionError) {
20
- return message;
21
- }
22
- err = new ConnectionError(message, code);
23
- Error.captureStackTrace(err, arguments.callee);
24
- return err;
1
+ 'use strict';
2
+
3
+ var util = require('util');
4
+
5
+ module.exports.ConnectionError = ConnectionError;
6
+ function ConnectionError(message, code) {
7
+ if (!(this instanceof ConnectionError)) {
8
+ if (message instanceof ConnectionError) {
9
+ return message;
25
10
  }
26
- this.name = this.constructor.name;
27
- this.message = message;
28
- this.code = code;
29
- ConnectionError.__super__.constructor.call(this);
30
- Error.captureStackTrace(this, this.constructor);
11
+
12
+ return new ConnectionError(message, code);
31
13
  }
32
14
 
33
- return ConnectionError;
34
- })(Error);
35
-
36
- RequestError = (function (superClass) {
37
- extend(RequestError, superClass);
38
-
39
- function RequestError(message, code) {
40
- var err;
41
- if (!(this instanceof RequestError)) {
42
- if (message instanceof RequestError) {
43
- return message;
44
- }
45
- err = new RequestError(message, code);
46
- Error.captureStackTrace(err, arguments.callee);
47
- return err;
15
+ Error.call(this);
16
+
17
+ this.message = message;
18
+ this.code = code;
19
+
20
+ Error.captureStackTrace(this, this.constructor);
21
+ }
22
+
23
+ util.inherits(ConnectionError, Error);
24
+
25
+ ConnectionError.prototype.name = 'ConnectionError';
26
+
27
+ module.exports.RequestError = RequestError;
28
+ function RequestError(message, code) {
29
+ if (!(this instanceof RequestError)) {
30
+ if (message instanceof RequestError) {
31
+ return message;
48
32
  }
49
- this.name = this.constructor.name;
50
- this.message = message;
51
- this.code = code;
52
- RequestError.__super__.constructor.call(this);
53
- Error.captureStackTrace(this, this.constructor);
33
+
34
+ return new RequestError(message, code);
54
35
  }
55
36
 
56
- return RequestError;
57
- })(Error);
37
+ Error.call(this);
38
+
39
+ this.message = message;
40
+ this.code = code;
41
+
42
+ Error.captureStackTrace(this, this.constructor);
43
+ }
44
+
45
+ util.inherits(RequestError, Error);
58
46
 
59
- module.exports = {
60
- ConnectionError: ConnectionError,
61
- RequestError: RequestError
62
- };
47
+ RequestError.prototype.name = 'RequestError';
@@ -1,43 +1,19 @@
1
- // Generated by CoffeeScript 1.10.0
2
- var arrayToGuid, formatHex, guidToArray;
1
+ 'use strict';
3
2
 
4
- guidToArray = function (guid) {
5
- var b1, b10, b11, b12, b13, b14, b15, b16, b2, b3, b4, b5, b6, b7, b8, b9, final;
6
- b1 = parseInt(guid.substring(6, 8), 16);
7
- b2 = parseInt(guid.substring(4, 6), 16);
8
- b3 = parseInt(guid.substring(2, 4), 16);
9
- b4 = parseInt(guid.substring(0, 2), 16);
10
- b5 = parseInt(guid.substring(11, 13), 16);
11
- b6 = parseInt(guid.substring(9, 11), 16);
12
- b7 = parseInt(guid.substring(16, 18), 16);
13
- b8 = parseInt(guid.substring(14, 16), 16);
14
- b9 = parseInt(guid.substring(19, 21), 16);
15
- b10 = parseInt(guid.substring(21, 23), 16);
16
- b11 = parseInt(guid.substring(24, 26), 16);
17
- b12 = parseInt(guid.substring(26, 28), 16);
18
- b13 = parseInt(guid.substring(28, 30), 16);
19
- b14 = parseInt(guid.substring(30, 32), 16);
20
- b15 = parseInt(guid.substring(32, 34), 16);
21
- b16 = parseInt(guid.substring(34, 36), 16);
22
- final = [b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16];
23
- return final;
24
- };
25
-
26
- exports.guidToArray = guidToArray;
27
-
28
- formatHex = function (number) {
29
- var hex;
30
- hex = number.toString(16);
3
+ function formatHex(number) {
4
+ var hex = number.toString(16);
31
5
  if (hex.length === 1) {
32
6
  hex = '0' + hex;
33
7
  }
34
8
  return hex;
35
- };
9
+ }
36
10
 
37
- arrayToGuid = function (array) {
38
- var guid;
39
- guid = formatHex(array[3]) + formatHex(array[2]) + formatHex(array[1]) + formatHex(array[0]) + '-' + formatHex(array[5]) + formatHex(array[4]) + '-' + formatHex(array[7]) + formatHex(array[6]) + '-' + formatHex(array[8]) + formatHex(array[9]) + '-' + formatHex(array[10]) + formatHex(array[11]) + formatHex(array[12]) + formatHex(array[13]) + formatHex(array[14]) + formatHex(array[15]);
40
- return guid.toUpperCase();
41
- };
11
+ module.exports.arrayToGuid = arrayToGuid;
12
+ function arrayToGuid(array) {
13
+ return (formatHex(array[3]) + formatHex(array[2]) + formatHex(array[1]) + formatHex(array[0]) + '-' + formatHex(array[5]) + formatHex(array[4]) + '-' + formatHex(array[7]) + formatHex(array[6]) + '-' + formatHex(array[8]) + formatHex(array[9]) + '-' + formatHex(array[10]) + formatHex(array[11]) + formatHex(array[12]) + formatHex(array[13]) + formatHex(array[14]) + formatHex(array[15])).toUpperCase();
14
+ }
42
15
 
43
- exports.arrayToGuid = arrayToGuid;
16
+ module.exports.guidToArray = guidToArray;
17
+ function guidToArray(guid) {
18
+ return [parseInt(guid.substring(6, 8), 16), parseInt(guid.substring(4, 6), 16), parseInt(guid.substring(2, 4), 16), parseInt(guid.substring(0, 2), 16), parseInt(guid.substring(11, 13), 16), parseInt(guid.substring(9, 11), 16), parseInt(guid.substring(16, 18), 16), parseInt(guid.substring(14, 16), 16), parseInt(guid.substring(19, 21), 16), parseInt(guid.substring(21, 23), 16), parseInt(guid.substring(24, 26), 16), parseInt(guid.substring(26, 28), 16), parseInt(guid.substring(28, 30), 16), parseInt(guid.substring(30, 32), 16), parseInt(guid.substring(32, 34), 16), parseInt(guid.substring(34, 36), 16)];
19
+ }
@@ -1,81 +1,87 @@
1
- // Generated by CoffeeScript 1.10.0
2
- var MYSTERY_HEADER_LENGTH, RETRIES, SQL_SERVER_BROWSER_PORT, TIMEOUT, dgram, parseBrowserResponse;
1
+ 'use strict';
3
2
 
4
- dgram = require('dgram');
3
+ var dgram = require('dgram');
5
4
 
6
- SQL_SERVER_BROWSER_PORT = 1434;
5
+ var SQL_SERVER_BROWSER_PORT = 1434;
6
+ var TIMEOUT = 2 * 1000;
7
+ var RETRIES = 3;
8
+ // There are three bytes at the start of the response, whose purpose is unknown.
9
+ var MYSTERY_HEADER_LENGTH = 3;
7
10
 
8
- TIMEOUT = 2 * 1000;
9
-
10
- RETRIES = 3;
11
-
12
- MYSTERY_HEADER_LENGTH = 3;
13
-
14
- exports.instanceLookup = function (server, instanceName, callback, timeout, retries) {
15
- var error, makeAttempt, message, retriesLeft, socket, timedOut, timer;
11
+ // Most of the functionality has been determined from from jTDS's MSSqlServerInfo class.
12
+ module.exports.instanceLookup = instanceLookup;
13
+ function instanceLookup(server, instanceName, callback, timeout, retries) {
14
+ var socket = undefined,
15
+ timer = undefined;
16
16
  timeout = timeout || TIMEOUT;
17
- retriesLeft = retries || RETRIES;
18
- timer = void 0;
19
- socket = void 0;
20
- message = function (message, rinfo) {
21
- var port;
17
+ var retriesLeft = retries || RETRIES;
18
+
19
+ function onMessage(message) {
22
20
  if (timer) {
23
21
  clearTimeout(timer);
24
- timer = void 0;
22
+ timer = undefined;
25
23
  }
26
24
  message = message.toString('ascii', MYSTERY_HEADER_LENGTH);
27
- port = parseBrowserResponse(message, instanceName);
25
+ var port = parseBrowserResponse(message, instanceName);
28
26
  socket.close();
29
27
  if (port) {
30
- return callback(void 0, port);
28
+ return callback(undefined, port);
31
29
  } else {
32
- return callback("Port for " + instanceName + " not found in " + message);
30
+ return callback('Port for ' + instanceName + ' not found in ' + message);
33
31
  }
34
- };
35
- error = function (err) {
32
+ }
33
+
34
+ function onError(err) {
36
35
  if (timer) {
37
36
  clearTimeout(timer);
38
- timer = void 0;
37
+ timer = undefined;
39
38
  }
40
39
  socket.close();
41
- return callback("Failed to lookup instance on " + server + " - " + err.message);
42
- };
43
- timedOut = function () {
44
- timer = void 0;
40
+ return callback('Failed to lookup instance on ' + server + ' - ' + err.message);
41
+ }
42
+
43
+ function onTimeout() {
44
+ timer = undefined;
45
45
  socket.close();
46
46
  return makeAttempt();
47
- };
48
- makeAttempt = function () {
49
- var request;
47
+ }
48
+
49
+ function makeAttempt() {
50
50
  if (retriesLeft > 0) {
51
51
  retriesLeft--;
52
- request = new Buffer([0x02]);
52
+ var request = new Buffer([0x02]);
53
53
  socket = dgram.createSocket('udp4');
54
- socket.on('error', error);
55
- socket.on('message', message);
54
+ socket.on('error', onError);
55
+ socket.on('message', onMessage);
56
56
  socket.send(request, 0, request.length, SQL_SERVER_BROWSER_PORT, server);
57
- return timer = setTimeout(timedOut, timeout);
57
+ return timer = setTimeout(onTimeout, timeout);
58
58
  } else {
59
- return callback("Failed to get response from SQL Server Browser on " + server);
59
+ return callback('Failed to get response from SQL Server Browser on ' + server);
60
60
  }
61
- };
61
+ }
62
+
62
63
  return makeAttempt();
63
- };
64
+ }
65
+
66
+ module.exports.parseBrowserResponse = parseBrowserResponse;
67
+ function parseBrowserResponse(response, instanceName) {
68
+ var getPort = undefined;
64
69
 
65
- parseBrowserResponse = function (response, instanceName) {
66
- var getPort, i, instance, instances, j, len, name, p, parts, port, ref, value;
67
- instances = response.split(';;');
68
- for (i = 0, len = instances.length; i < len; i++) {
69
- instance = instances[i];
70
- parts = instance.split(';');
71
- for (p = j = 0, ref = parts.length - 1; j <= ref; p = j += 2) {
72
- name = parts[p];
73
- value = parts[p + 1];
74
- if (name === 'tcp' && getPort) {
75
- port = parseInt(value, 10);
70
+ var instances = response.split(';;');
71
+ for (var i = 0, len = instances.length; i < len; i++) {
72
+ var instance = instances[i];
73
+ var parts = instance.split(';');
74
+
75
+ for (var p = 0, partsLen = parts.length; p < partsLen; p += 2) {
76
+ var _name = parts[p];
77
+ var value = parts[p + 1];
78
+
79
+ if (_name === 'tcp' && getPort) {
80
+ var port = parseInt(value, 10);
76
81
  return port;
77
82
  }
78
- if (name === 'InstanceName') {
83
+
84
+ if (_name === 'InstanceName') {
79
85
  if (value.toUpperCase() === instanceName.toUpperCase()) {
80
86
  getPort = true;
81
87
  } else {
@@ -84,7 +90,4 @@ parseBrowserResponse = function (response, instanceName) {
84
90
  }
85
91
  }
86
92
  }
87
- return void 0;
88
- };
89
-
90
- exports.parseBrowserResponse = parseBrowserResponse;
93
+ }
package/lib/library.js CHANGED
@@ -1,2 +1,3 @@
1
- // Generated by CoffeeScript 1.10.0
2
- exports.name = 'Tedious';
1
+ 'use strict';
2
+
3
+ module.exports.name = 'Tedious';