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.
- package/README.md +1 -1
- package/appveyor.yml +9 -5
- package/benchmarks/README.md +33 -0
- package/benchmarks/common.js +82 -0
- package/benchmarks/index.js +34 -0
- package/benchmarks/query/many-result-rows.js +49 -0
- package/benchmarks/query/nvarchar-large.js +44 -0
- package/benchmarks/query/nvarchar-small.js +44 -0
- package/benchmarks/query/varbinary-4.js +42 -0
- package/benchmarks/query/varbinary-huge.js +46 -0
- package/benchmarks/query/varbinary-large.js +46 -0
- package/benchmarks/query/varbinary-small.js +42 -0
- package/benchmarks/token-parser/colmetadata-token.js +42 -0
- package/benchmarks/token-parser/done-token.js +42 -0
- package/benchmarks/token-parser/simple-tokens.js +366 -0
- package/lib/all-headers.js +9 -11
- package/lib/buffertools.js +17 -13
- package/lib/bulk-load.js +196 -169
- package/lib/collation.js +80 -2
- package/lib/connection.js +1086 -1060
- package/lib/data-type.js +450 -253
- package/lib/debug.js +57 -51
- package/lib/errors.js +40 -55
- package/lib/guid-parser.js +12 -36
- package/lib/instance-lookup.js +57 -54
- package/lib/library.js +3 -2
- package/lib/login7-payload.js +187 -180
- package/lib/message-io.js +169 -199
- package/lib/metadata-parser.js +169 -255
- package/lib/ntlm-payload.js +173 -160
- package/lib/packet.js +166 -152
- package/lib/prelogin-payload.js +170 -160
- package/lib/request.js +122 -122
- package/lib/rpcrequest-payload.js +64 -38
- package/lib/special-stored-procedure.js +3 -2
- package/lib/sqlbatch-payload.js +20 -16
- package/lib/stream-parser.js +116 -104
- package/lib/tds-versions.js +5 -8
- package/lib/tedious.js +8 -14
- package/lib/token/colmetadata-token-parser.js +79 -125
- package/lib/token/done-token-parser.js +47 -129
- package/lib/token/env-change-token-parser.js +90 -126
- package/lib/token/infoerror-token-parser.js +47 -125
- package/lib/token/loginack-token-parser.js +36 -74
- package/lib/token/nbcrow-token-parser.js +40 -64
- package/lib/token/order-token-parser.js +26 -43
- package/lib/token/returnstatus-token-parser.js +11 -23
- package/lib/token/returnvalue-token-parser.js +31 -54
- package/lib/token/row-token-parser.js +39 -52
- package/lib/token/sspi-token-parser.js +14 -32
- package/lib/token/stream-parser.js +424 -304
- package/lib/token/token-stream-parser.js +39 -34
- package/lib/token/token.js +3 -6
- package/lib/tracking-buffer/bigint.js +45 -48
- package/lib/tracking-buffer/readable-tracking-buffer.js +238 -223
- package/lib/tracking-buffer/tracking-buffer.js +3 -9
- package/lib/tracking-buffer/writable-tracking-buffer.js +272 -244
- package/lib/transaction.js +112 -102
- package/lib/value-parser.js +559 -1154
- package/package.json +10 -9
- package/benchmarks/benchmarks.coffee +0 -122
- package/benchmarks/query.coffee +0 -57
package/lib/debug.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
3
|
+
var _get = require('babel-runtime/helpers/get')['default'];
|
|
15
4
|
|
|
16
|
-
|
|
5
|
+
var _inherits = require('babel-runtime/helpers/inherits')['default'];
|
|
17
6
|
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
60
|
-
ConnectionError: ConnectionError,
|
|
61
|
-
RequestError: RequestError
|
|
62
|
-
};
|
|
47
|
+
RequestError.prototype.name = 'RequestError';
|
package/lib/guid-parser.js
CHANGED
|
@@ -1,43 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
var arrayToGuid, formatHex, guidToArray;
|
|
1
|
+
'use strict';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
var
|
|
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 =
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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.
|
|
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
|
+
}
|
package/lib/instance-lookup.js
CHANGED
|
@@ -1,81 +1,87 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
19
|
-
|
|
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 =
|
|
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(
|
|
28
|
+
return callback(undefined, port);
|
|
31
29
|
} else {
|
|
32
|
-
return callback(
|
|
30
|
+
return callback('Port for ' + instanceName + ' not found in ' + message);
|
|
33
31
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function onError(err) {
|
|
36
35
|
if (timer) {
|
|
37
36
|
clearTimeout(timer);
|
|
38
|
-
timer =
|
|
37
|
+
timer = undefined;
|
|
39
38
|
}
|
|
40
39
|
socket.close();
|
|
41
|
-
return callback(
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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',
|
|
55
|
-
socket.on('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(
|
|
57
|
+
return timer = setTimeout(onTimeout, timeout);
|
|
58
58
|
} else {
|
|
59
|
-
return callback(
|
|
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
|
-
|
|
66
|
-
var
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
exports.parseBrowserResponse = parseBrowserResponse;
|
|
93
|
+
}
|
package/lib/library.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.name = 'Tedious';
|