tedious 2.2.0 → 2.2.4
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/lib/bulk-load.js +1 -1
- package/lib/connection.js +148 -131
- package/lib/data-type.js +79 -1669
- package/lib/data-types/bigint.js +46 -0
- package/lib/data-types/binary.js +57 -0
- package/lib/data-types/bit.js +38 -0
- package/lib/data-types/bitn.js +8 -0
- package/lib/data-types/char.js +72 -0
- package/lib/data-types/daten.js +48 -0
- package/lib/data-types/datetime.js +68 -0
- package/lib/data-types/datetime2n.js +105 -0
- package/lib/data-types/datetimen.js +8 -0
- package/lib/data-types/datetimeoffsetn.js +91 -0
- package/lib/data-types/decimal.js +88 -0
- package/lib/data-types/decimaln.js +10 -0
- package/lib/data-types/float.js +38 -0
- package/lib/data-types/floatn.js +8 -0
- package/lib/data-types/image.js +46 -0
- package/lib/data-types/int.js +41 -0
- package/lib/data-types/intn.js +8 -0
- package/lib/data-types/money.js +38 -0
- package/lib/data-types/moneyn.js +8 -0
- package/lib/data-types/nchar.js +72 -0
- package/lib/data-types/ntext.js +11 -0
- package/lib/data-types/null.js +7 -0
- package/lib/data-types/numeric.js +88 -0
- package/lib/data-types/numericn.js +10 -0
- package/lib/data-types/nvarchar.js +86 -0
- package/lib/data-types/real.js +38 -0
- package/lib/data-types/smalldatetime.js +60 -0
- package/lib/data-types/smallint.js +41 -0
- package/lib/data-types/smallmoney.js +41 -0
- package/lib/data-types/sql-variant.js +12 -0
- package/lib/data-types/text.js +51 -0
- package/lib/data-types/timen.js +95 -0
- package/lib/data-types/tinyint.js +41 -0
- package/lib/data-types/tvp.js +83 -0
- package/lib/data-types/udt.js +8 -0
- package/lib/data-types/uniqueidentifiern.js +46 -0
- package/lib/data-types/varbinary.js +77 -0
- package/lib/data-types/varchar.js +86 -0
- package/lib/data-types/xml.js +8 -0
- package/lib/instance-lookup.js +8 -7
- package/lib/message-io.js +1 -1
- package/lib/ntlm-payload.js +5 -5
- package/lib/packet.js +3 -3
- package/lib/prelogin-payload.js +7 -7
- package/lib/request.js +37 -16
- package/lib/tracking-buffer/bigint.js +1 -1
- package/lib/tracking-buffer/writable-tracking-buffer.js +52 -48
- package/lib/value-parser.js +13 -13
- package/package.json +1 -1
package/lib/connection.js
CHANGED
|
@@ -425,13 +425,13 @@ var Connection = function (_EventEmitter) {
|
|
|
425
425
|
(0, _createClass3.default)(Connection, [{
|
|
426
426
|
key: 'close',
|
|
427
427
|
value: function close() {
|
|
428
|
-
|
|
428
|
+
this.transitionTo(this.STATE.FINAL);
|
|
429
429
|
}
|
|
430
430
|
}, {
|
|
431
431
|
key: 'initialiseConnection',
|
|
432
432
|
value: function initialiseConnection() {
|
|
433
433
|
this.connect();
|
|
434
|
-
|
|
434
|
+
this.createConnectTimer();
|
|
435
435
|
}
|
|
436
436
|
}, {
|
|
437
437
|
key: 'cleanupConnection',
|
|
@@ -453,7 +453,7 @@ var Connection = function (_EventEmitter) {
|
|
|
453
453
|
}
|
|
454
454
|
this.closed = true;
|
|
455
455
|
this.loggedIn = false;
|
|
456
|
-
|
|
456
|
+
this.loginError = null;
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
459
|
}, {
|
|
@@ -462,8 +462,8 @@ var Connection = function (_EventEmitter) {
|
|
|
462
462
|
var _this2 = this;
|
|
463
463
|
|
|
464
464
|
this.debug = new Debug(this.config.options.debug);
|
|
465
|
-
|
|
466
|
-
|
|
465
|
+
this.debug.on('debug', function (message) {
|
|
466
|
+
_this2.emit('debug', message);
|
|
467
467
|
});
|
|
468
468
|
}
|
|
469
469
|
}, {
|
|
@@ -474,7 +474,7 @@ var Connection = function (_EventEmitter) {
|
|
|
474
474
|
this.tokenStreamParser = new TokenStreamParser(this.debug, undefined, this.config.options);
|
|
475
475
|
|
|
476
476
|
this.tokenStreamParser.on('infoMessage', function (token) {
|
|
477
|
-
|
|
477
|
+
_this3.emit('infoMessage', token);
|
|
478
478
|
});
|
|
479
479
|
|
|
480
480
|
this.tokenStreamParser.on('sspichallenge', function (token) {
|
|
@@ -482,7 +482,8 @@ var Connection = function (_EventEmitter) {
|
|
|
482
482
|
_this3.ntlmpacket = token.ntlmpacket;
|
|
483
483
|
_this3.ntlmpacketBuffer = token.ntlmpacketBuffer;
|
|
484
484
|
}
|
|
485
|
-
|
|
485
|
+
|
|
486
|
+
_this3.emit('sspichallenge', token);
|
|
486
487
|
});
|
|
487
488
|
|
|
488
489
|
this.tokenStreamParser.on('errorMessage', function (token) {
|
|
@@ -509,15 +510,15 @@ var Connection = function (_EventEmitter) {
|
|
|
509
510
|
});
|
|
510
511
|
|
|
511
512
|
this.tokenStreamParser.on('databaseChange', function (token) {
|
|
512
|
-
|
|
513
|
+
_this3.emit('databaseChange', token.newValue);
|
|
513
514
|
});
|
|
514
515
|
|
|
515
516
|
this.tokenStreamParser.on('languageChange', function (token) {
|
|
516
|
-
|
|
517
|
+
_this3.emit('languageChange', token.newValue);
|
|
517
518
|
});
|
|
518
519
|
|
|
519
520
|
this.tokenStreamParser.on('charsetChange', function (token) {
|
|
520
|
-
|
|
521
|
+
_this3.emit('charsetChange', token.newValue);
|
|
521
522
|
});
|
|
522
523
|
|
|
523
524
|
this.tokenStreamParser.on('loginack', function (token) {
|
|
@@ -537,30 +538,30 @@ var Connection = function (_EventEmitter) {
|
|
|
537
538
|
|
|
538
539
|
// use negotiated version
|
|
539
540
|
_this3.config.options.tdsVersion = token.tdsVersion;
|
|
540
|
-
|
|
541
|
+
_this3.loggedIn = true;
|
|
541
542
|
});
|
|
542
543
|
|
|
543
544
|
this.tokenStreamParser.on('routingChange', function (token) {
|
|
544
545
|
_this3.routingData = token.newValue;
|
|
545
|
-
|
|
546
|
+
_this3.dispatchEvent('routingChange');
|
|
546
547
|
});
|
|
547
548
|
|
|
548
549
|
this.tokenStreamParser.on('packetSizeChange', function (token) {
|
|
549
|
-
|
|
550
|
+
_this3.messageIo.packetSize(token.newValue);
|
|
550
551
|
});
|
|
551
552
|
|
|
552
553
|
// A new top-level transaction was started. This is not fired
|
|
553
554
|
// for nested transactions.
|
|
554
555
|
this.tokenStreamParser.on('beginTransaction', function (token) {
|
|
555
556
|
_this3.transactionDescriptors.push(token.newValue);
|
|
556
|
-
|
|
557
|
+
_this3.inTransaction = true;
|
|
557
558
|
});
|
|
558
559
|
|
|
559
560
|
// A top-level transaction was committed. This is not fired
|
|
560
561
|
// for nested transactions.
|
|
561
562
|
this.tokenStreamParser.on('commitTransaction', function () {
|
|
562
563
|
_this3.transactionDescriptors.length = 1;
|
|
563
|
-
|
|
564
|
+
_this3.inTransaction = false;
|
|
564
565
|
});
|
|
565
566
|
|
|
566
567
|
// A top-level transaction was rolled back. This is not fired
|
|
@@ -570,7 +571,7 @@ var Connection = function (_EventEmitter) {
|
|
|
570
571
|
_this3.transactionDescriptors.length = 1;
|
|
571
572
|
// An outermost transaction was rolled back. Reset the transaction counter
|
|
572
573
|
_this3.inTransaction = false;
|
|
573
|
-
|
|
574
|
+
_this3.emit('rollbackTransaction');
|
|
574
575
|
});
|
|
575
576
|
|
|
576
577
|
this.tokenStreamParser.on('columnMetadata', function (token) {
|
|
@@ -587,19 +588,19 @@ var Connection = function (_EventEmitter) {
|
|
|
587
588
|
} else {
|
|
588
589
|
columns = token.columns;
|
|
589
590
|
}
|
|
590
|
-
|
|
591
|
+
_this3.request.emit('columnMetadata', columns);
|
|
591
592
|
} else {
|
|
592
593
|
_this3.emit('error', new Error("Received 'columnMetadata' when no sqlRequest is in progress"));
|
|
593
|
-
|
|
594
|
+
_this3.close();
|
|
594
595
|
}
|
|
595
596
|
});
|
|
596
597
|
|
|
597
598
|
this.tokenStreamParser.on('order', function (token) {
|
|
598
599
|
if (_this3.request) {
|
|
599
|
-
|
|
600
|
+
_this3.request.emit('order', token.orderColumns);
|
|
600
601
|
} else {
|
|
601
602
|
_this3.emit('error', new Error("Received 'order' when no sqlRequest is in progress"));
|
|
602
|
-
|
|
603
|
+
_this3.close();
|
|
603
604
|
}
|
|
604
605
|
});
|
|
605
606
|
|
|
@@ -616,20 +617,20 @@ var Connection = function (_EventEmitter) {
|
|
|
616
617
|
}
|
|
617
618
|
} else {
|
|
618
619
|
_this3.emit('error', new Error("Received 'row' when no sqlRequest is in progress"));
|
|
619
|
-
|
|
620
|
+
_this3.close();
|
|
620
621
|
}
|
|
621
622
|
});
|
|
622
623
|
|
|
623
624
|
this.tokenStreamParser.on('returnStatus', function (token) {
|
|
624
625
|
if (_this3.request) {
|
|
625
626
|
// Keep value for passing in 'doneProc' event.
|
|
626
|
-
|
|
627
|
+
_this3.procReturnStatusValue = token.value;
|
|
627
628
|
}
|
|
628
629
|
});
|
|
629
630
|
|
|
630
631
|
this.tokenStreamParser.on('returnValue', function (token) {
|
|
631
632
|
if (_this3.request) {
|
|
632
|
-
|
|
633
|
+
_this3.request.emit('returnValue', token.paramName, token.value, token.metadata);
|
|
633
634
|
}
|
|
634
635
|
});
|
|
635
636
|
|
|
@@ -641,7 +642,7 @@ var Connection = function (_EventEmitter) {
|
|
|
641
642
|
_this3.request.rowCount += token.rowCount;
|
|
642
643
|
}
|
|
643
644
|
if (_this3.config.options.rowCollectionOnDone) {
|
|
644
|
-
|
|
645
|
+
_this3.request.rst = [];
|
|
645
646
|
}
|
|
646
647
|
}
|
|
647
648
|
});
|
|
@@ -653,7 +654,7 @@ var Connection = function (_EventEmitter) {
|
|
|
653
654
|
_this3.request.rowCount += token.rowCount;
|
|
654
655
|
}
|
|
655
656
|
if (_this3.config.options.rowCollectionOnDone) {
|
|
656
|
-
|
|
657
|
+
_this3.request.rst = [];
|
|
657
658
|
}
|
|
658
659
|
}
|
|
659
660
|
});
|
|
@@ -672,7 +673,7 @@ var Connection = function (_EventEmitter) {
|
|
|
672
673
|
_this3.request.rowCount += token.rowCount;
|
|
673
674
|
}
|
|
674
675
|
if (_this3.config.options.rowCollectionOnDone) {
|
|
675
|
-
|
|
676
|
+
_this3.request.rst = [];
|
|
676
677
|
}
|
|
677
678
|
}
|
|
678
679
|
});
|
|
@@ -685,12 +686,12 @@ var Connection = function (_EventEmitter) {
|
|
|
685
686
|
});
|
|
686
687
|
|
|
687
688
|
this.tokenStreamParser.on('resetConnection', function () {
|
|
688
|
-
|
|
689
|
+
_this3.emit('resetConnection');
|
|
689
690
|
});
|
|
690
691
|
|
|
691
692
|
this.tokenStreamParser.on('tokenStreamError', function (error) {
|
|
692
693
|
_this3.emit('error', error);
|
|
693
|
-
|
|
694
|
+
_this3.close();
|
|
694
695
|
});
|
|
695
696
|
|
|
696
697
|
this.tokenStreamParser.on('drain', function () {
|
|
@@ -716,9 +717,9 @@ var Connection = function (_EventEmitter) {
|
|
|
716
717
|
return;
|
|
717
718
|
}
|
|
718
719
|
if (message) {
|
|
719
|
-
|
|
720
|
+
_this4.emit('connect', ConnectionError(message, 'EINSTLOOKUP'));
|
|
720
721
|
} else {
|
|
721
|
-
|
|
722
|
+
_this4.connectOnPort(port, _this4.config.options.multiSubnetFailover);
|
|
722
723
|
}
|
|
723
724
|
});
|
|
724
725
|
}
|
|
@@ -739,6 +740,11 @@ var Connection = function (_EventEmitter) {
|
|
|
739
740
|
return _this5.socketError(err);
|
|
740
741
|
}
|
|
741
742
|
|
|
743
|
+
if (_this5.state === _this5.STATE.FINAL) {
|
|
744
|
+
socket.destroy();
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
|
|
742
748
|
_this5.socket = socket;
|
|
743
749
|
_this5.socket.on('error', _this5.socketError);
|
|
744
750
|
_this5.socket.on('close', _this5.socketClose);
|
|
@@ -765,14 +771,14 @@ var Connection = function (_EventEmitter) {
|
|
|
765
771
|
}, {
|
|
766
772
|
key: 'createConnectTimer',
|
|
767
773
|
value: function createConnectTimer() {
|
|
768
|
-
|
|
774
|
+
this.connectTimer = setTimeout(this.connectTimeout, this.config.options.connectTimeout);
|
|
769
775
|
}
|
|
770
776
|
}, {
|
|
771
777
|
key: 'createRequestTimer',
|
|
772
778
|
value: function createRequestTimer() {
|
|
773
779
|
this.clearRequestTimer(); // release old timer, just to be safe
|
|
774
780
|
if (this.config.options.requestTimeout) {
|
|
775
|
-
|
|
781
|
+
this.requestTimer = setTimeout(this.requestTimeout, this.config.options.requestTimeout);
|
|
776
782
|
}
|
|
777
783
|
}
|
|
778
784
|
}, {
|
|
@@ -788,14 +794,14 @@ var Connection = function (_EventEmitter) {
|
|
|
788
794
|
this.debug.log(message);
|
|
789
795
|
this.emit('connect', ConnectionError(message, 'ETIMEOUT'));
|
|
790
796
|
this.connectTimer = undefined;
|
|
791
|
-
|
|
797
|
+
this.dispatchEvent('connectTimeout');
|
|
792
798
|
}
|
|
793
799
|
}, {
|
|
794
800
|
key: 'requestTimeout',
|
|
795
801
|
value: function requestTimeout() {
|
|
796
802
|
this.requestTimer = undefined;
|
|
797
803
|
this.messageIo.sendMessage(TYPE.ATTENTION);
|
|
798
|
-
|
|
804
|
+
this.transitionTo(this.STATE.SENT_ATTENTION);
|
|
799
805
|
}
|
|
800
806
|
}, {
|
|
801
807
|
key: 'retryTimeout',
|
|
@@ -808,7 +814,7 @@ var Connection = function (_EventEmitter) {
|
|
|
808
814
|
key: 'clearConnectTimer',
|
|
809
815
|
value: function clearConnectTimer() {
|
|
810
816
|
if (this.connectTimer) {
|
|
811
|
-
|
|
817
|
+
clearTimeout(this.connectTimer);
|
|
812
818
|
}
|
|
813
819
|
}
|
|
814
820
|
}, {
|
|
@@ -843,7 +849,7 @@ var Connection = function (_EventEmitter) {
|
|
|
843
849
|
this.state = newState;
|
|
844
850
|
|
|
845
851
|
if (this.state.enter) {
|
|
846
|
-
|
|
852
|
+
this.state.enter.apply(this);
|
|
847
853
|
}
|
|
848
854
|
}
|
|
849
855
|
}, {
|
|
@@ -854,10 +860,10 @@ var Connection = function (_EventEmitter) {
|
|
|
854
860
|
for (var i = 0; i < args.length;) {
|
|
855
861
|
args[i++] = arguments[i];
|
|
856
862
|
}
|
|
857
|
-
|
|
863
|
+
this.state.events[eventName].apply(this, args);
|
|
858
864
|
} else {
|
|
859
865
|
this.emit('error', new Error(`No event '${eventName}' in state '${this.state.name}'`));
|
|
860
|
-
|
|
866
|
+
this.close();
|
|
861
867
|
}
|
|
862
868
|
}
|
|
863
869
|
}, {
|
|
@@ -872,7 +878,7 @@ var Connection = function (_EventEmitter) {
|
|
|
872
878
|
this.debug.log(_message);
|
|
873
879
|
this.emit('error', ConnectionError(_message, 'ESOCKET'));
|
|
874
880
|
}
|
|
875
|
-
|
|
881
|
+
this.dispatchEvent('socketError', error);
|
|
876
882
|
}
|
|
877
883
|
}, {
|
|
878
884
|
key: 'socketConnect',
|
|
@@ -880,13 +886,13 @@ var Connection = function (_EventEmitter) {
|
|
|
880
886
|
this.socket.setKeepAlive(true, KEEP_ALIVE_INITIAL_DELAY);
|
|
881
887
|
this.closed = false;
|
|
882
888
|
this.debug.log('connected to ' + this.config.server + ':' + this.config.options.port);
|
|
883
|
-
|
|
889
|
+
this.dispatchEvent('socketConnect');
|
|
884
890
|
}
|
|
885
891
|
}, {
|
|
886
892
|
key: 'socketEnd',
|
|
887
893
|
value: function socketEnd() {
|
|
888
894
|
this.debug.log('socket ended');
|
|
889
|
-
|
|
895
|
+
this.transitionTo(this.STATE.FINAL);
|
|
890
896
|
}
|
|
891
897
|
}, {
|
|
892
898
|
key: 'socketClose',
|
|
@@ -894,15 +900,15 @@ var Connection = function (_EventEmitter) {
|
|
|
894
900
|
this.debug.log('connection to ' + this.config.server + ':' + this.config.options.port + ' closed');
|
|
895
901
|
if (this.state === this.STATE.REROUTING) {
|
|
896
902
|
this.debug.log('Rerouting to ' + this.routingData.server + ':' + this.routingData.port);
|
|
897
|
-
|
|
903
|
+
this.dispatchEvent('reconnect');
|
|
898
904
|
} else if (this.state === this.STATE.TRANSIENT_FAILURE_RETRY) {
|
|
899
905
|
var server = this.routingData ? this.routingData.server : this.server;
|
|
900
906
|
var port = this.routingData ? this.routingData.port : this.config.options.port;
|
|
901
907
|
this.debug.log('Retry after transient failure connecting to ' + server + ':' + port);
|
|
902
908
|
|
|
903
|
-
|
|
909
|
+
this.dispatchEvent('retry');
|
|
904
910
|
} else {
|
|
905
|
-
|
|
911
|
+
this.transitionTo(this.STATE.FINAL);
|
|
906
912
|
}
|
|
907
913
|
}
|
|
908
914
|
}, {
|
|
@@ -912,19 +918,19 @@ var Connection = function (_EventEmitter) {
|
|
|
912
918
|
encrypt: this.config.options.encrypt
|
|
913
919
|
});
|
|
914
920
|
this.messageIo.sendMessage(TYPE.PRELOGIN, payload.data);
|
|
915
|
-
|
|
921
|
+
this.debug.payload(function () {
|
|
916
922
|
return payload.toString(' ');
|
|
917
923
|
});
|
|
918
924
|
}
|
|
919
925
|
}, {
|
|
920
926
|
key: 'emptyMessageBuffer',
|
|
921
927
|
value: function emptyMessageBuffer() {
|
|
922
|
-
|
|
928
|
+
this.messageBuffer = new Buffer(0);
|
|
923
929
|
}
|
|
924
930
|
}, {
|
|
925
931
|
key: 'addToMessageBuffer',
|
|
926
932
|
value: function addToMessageBuffer(data) {
|
|
927
|
-
|
|
933
|
+
this.messageBuffer = Buffer.concat([this.messageBuffer, data]);
|
|
928
934
|
}
|
|
929
935
|
}, {
|
|
930
936
|
key: 'processPreLoginResponse',
|
|
@@ -940,9 +946,9 @@ var Connection = function (_EventEmitter) {
|
|
|
940
946
|
return this.close();
|
|
941
947
|
}
|
|
942
948
|
|
|
943
|
-
|
|
949
|
+
this.dispatchEvent('tls');
|
|
944
950
|
} else {
|
|
945
|
-
|
|
951
|
+
this.dispatchEvent('noTls');
|
|
946
952
|
}
|
|
947
953
|
}
|
|
948
954
|
}, {
|
|
@@ -1130,54 +1136,54 @@ var Connection = function (_EventEmitter) {
|
|
|
1130
1136
|
key: 'processedInitialSql',
|
|
1131
1137
|
value: function processedInitialSql() {
|
|
1132
1138
|
this.clearConnectTimer();
|
|
1133
|
-
|
|
1139
|
+
this.emit('connect');
|
|
1134
1140
|
}
|
|
1135
1141
|
}, {
|
|
1136
1142
|
key: 'processLogin7Response',
|
|
1137
1143
|
value: function processLogin7Response() {
|
|
1138
1144
|
if (this.loggedIn) {
|
|
1139
|
-
|
|
1145
|
+
this.dispatchEvent('loggedIn');
|
|
1140
1146
|
} else {
|
|
1141
1147
|
if (this.loginError) {
|
|
1142
1148
|
this.emit('connect', this.loginError);
|
|
1143
1149
|
} else {
|
|
1144
1150
|
this.emit('connect', ConnectionError('Login failed.', 'ELOGIN'));
|
|
1145
1151
|
}
|
|
1146
|
-
|
|
1152
|
+
this.dispatchEvent('loginFailed');
|
|
1147
1153
|
}
|
|
1148
1154
|
}
|
|
1149
1155
|
}, {
|
|
1150
1156
|
key: 'processLogin7NTLMResponse',
|
|
1151
1157
|
value: function processLogin7NTLMResponse() {
|
|
1152
1158
|
if (this.ntlmpacket) {
|
|
1153
|
-
|
|
1159
|
+
this.dispatchEvent('receivedChallenge');
|
|
1154
1160
|
} else {
|
|
1155
1161
|
if (this.loginError) {
|
|
1156
1162
|
this.emit('connect', this.loginError);
|
|
1157
1163
|
} else {
|
|
1158
1164
|
this.emit('connect', ConnectionError('Login failed.', 'ELOGIN'));
|
|
1159
1165
|
}
|
|
1160
|
-
|
|
1166
|
+
this.dispatchEvent('loginFailed');
|
|
1161
1167
|
}
|
|
1162
1168
|
}
|
|
1163
1169
|
}, {
|
|
1164
1170
|
key: 'processLogin7NTLMAck',
|
|
1165
1171
|
value: function processLogin7NTLMAck() {
|
|
1166
1172
|
if (this.loggedIn) {
|
|
1167
|
-
|
|
1173
|
+
this.dispatchEvent('loggedIn');
|
|
1168
1174
|
} else {
|
|
1169
1175
|
if (this.loginError) {
|
|
1170
1176
|
this.emit('connect', this.loginError);
|
|
1171
1177
|
} else {
|
|
1172
1178
|
this.emit('connect', ConnectionError('Login failed.', 'ELOGIN'));
|
|
1173
1179
|
}
|
|
1174
|
-
|
|
1180
|
+
this.dispatchEvent('loginFailed');
|
|
1175
1181
|
}
|
|
1176
1182
|
}
|
|
1177
1183
|
}, {
|
|
1178
1184
|
key: 'execSqlBatch',
|
|
1179
1185
|
value: function execSqlBatch(request) {
|
|
1180
|
-
|
|
1186
|
+
this.makeRequest(request, TYPE.SQL_BATCH, new SqlBatchPayload(request.sqlTextOrProcedure, this.currentTransactionDescriptor(), this.config.options));
|
|
1181
1187
|
}
|
|
1182
1188
|
}, {
|
|
1183
1189
|
key: 'execSql',
|
|
@@ -1185,13 +1191,16 @@ var Connection = function (_EventEmitter) {
|
|
|
1185
1191
|
var _this6 = this;
|
|
1186
1192
|
|
|
1187
1193
|
request.transformIntoExecuteSqlRpc();
|
|
1194
|
+
|
|
1188
1195
|
if (request.error != null) {
|
|
1189
|
-
|
|
1196
|
+
process.nextTick(function () {
|
|
1190
1197
|
_this6.debug.log(request.error.message);
|
|
1191
|
-
|
|
1198
|
+
request.callback(request.error);
|
|
1192
1199
|
});
|
|
1200
|
+
return;
|
|
1193
1201
|
}
|
|
1194
|
-
|
|
1202
|
+
|
|
1203
|
+
this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
|
|
1195
1204
|
}
|
|
1196
1205
|
|
|
1197
1206
|
/**
|
|
@@ -1228,24 +1237,25 @@ var Connection = function (_EventEmitter) {
|
|
|
1228
1237
|
error.message += ' This is likely because the schema of the BulkLoad does not match the schema of the table you are attempting to insert into.';
|
|
1229
1238
|
}
|
|
1230
1239
|
bulkLoad.error = error;
|
|
1231
|
-
|
|
1240
|
+
bulkLoad.callback(error);
|
|
1232
1241
|
} else {
|
|
1233
|
-
|
|
1242
|
+
_this7.makeRequest(bulkLoad, TYPE.BULK_LOAD, bulkLoad.getPayload());
|
|
1234
1243
|
}
|
|
1235
1244
|
});
|
|
1236
|
-
|
|
1245
|
+
|
|
1246
|
+
this.execSqlBatch(request);
|
|
1237
1247
|
}
|
|
1238
1248
|
}, {
|
|
1239
1249
|
key: 'prepare',
|
|
1240
1250
|
value: function prepare(request) {
|
|
1241
1251
|
request.transformIntoPrepareRpc();
|
|
1242
|
-
|
|
1252
|
+
this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
|
|
1243
1253
|
}
|
|
1244
1254
|
}, {
|
|
1245
1255
|
key: 'unprepare',
|
|
1246
1256
|
value: function unprepare(request) {
|
|
1247
1257
|
request.transformIntoUnprepareRpc();
|
|
1248
|
-
|
|
1258
|
+
this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
|
|
1249
1259
|
}
|
|
1250
1260
|
}, {
|
|
1251
1261
|
key: 'execute',
|
|
@@ -1253,13 +1263,17 @@ var Connection = function (_EventEmitter) {
|
|
|
1253
1263
|
var _this8 = this;
|
|
1254
1264
|
|
|
1255
1265
|
request.transformIntoExecuteRpc(parameters);
|
|
1266
|
+
|
|
1256
1267
|
if (request.error != null) {
|
|
1257
|
-
|
|
1268
|
+
process.nextTick(function () {
|
|
1258
1269
|
_this8.debug.log(request.error.message);
|
|
1259
|
-
|
|
1270
|
+
request.callback(request.error);
|
|
1260
1271
|
});
|
|
1272
|
+
|
|
1273
|
+
return;
|
|
1261
1274
|
}
|
|
1262
|
-
|
|
1275
|
+
|
|
1276
|
+
this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
|
|
1263
1277
|
}
|
|
1264
1278
|
}, {
|
|
1265
1279
|
key: 'callProcedure',
|
|
@@ -1267,13 +1281,16 @@ var Connection = function (_EventEmitter) {
|
|
|
1267
1281
|
var _this9 = this;
|
|
1268
1282
|
|
|
1269
1283
|
request.validateParameters();
|
|
1284
|
+
|
|
1270
1285
|
if (request.error != null) {
|
|
1271
|
-
|
|
1286
|
+
process.nextTick(function () {
|
|
1272
1287
|
_this9.debug.log(request.error.message);
|
|
1273
|
-
|
|
1288
|
+
request.callback(request.error);
|
|
1274
1289
|
});
|
|
1290
|
+
return;
|
|
1275
1291
|
}
|
|
1276
|
-
|
|
1292
|
+
|
|
1293
|
+
this.makeRequest(request, TYPE.RPC_REQUEST, new RpcRequestPayload(request, this.currentTransactionDescriptor(), this.config.options));
|
|
1277
1294
|
}
|
|
1278
1295
|
}, {
|
|
1279
1296
|
key: 'beginTransaction',
|
|
@@ -1420,7 +1437,7 @@ var Connection = function (_EventEmitter) {
|
|
|
1420
1437
|
if (this.state !== this.STATE.LOGGED_IN) {
|
|
1421
1438
|
var message = 'Requests can only be made in the ' + this.STATE.LOGGED_IN.name + ' state, not the ' + this.state.name + ' state';
|
|
1422
1439
|
this.debug.log(message);
|
|
1423
|
-
|
|
1440
|
+
request.callback(RequestError(message, 'EINVALIDSTATE'));
|
|
1424
1441
|
} else {
|
|
1425
1442
|
if (packetType === TYPE.SQL_BATCH) {
|
|
1426
1443
|
this.isSqlBatch = true;
|
|
@@ -1504,71 +1521,71 @@ Connection.prototype.STATE = {
|
|
|
1504
1521
|
CONNECTING: {
|
|
1505
1522
|
name: 'Connecting',
|
|
1506
1523
|
enter: function enter() {
|
|
1507
|
-
|
|
1524
|
+
this.initialiseConnection();
|
|
1508
1525
|
},
|
|
1509
1526
|
events: {
|
|
1510
1527
|
socketError: function socketError() {
|
|
1511
|
-
|
|
1528
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1512
1529
|
},
|
|
1513
1530
|
connectTimeout: function connectTimeout() {
|
|
1514
|
-
|
|
1531
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1515
1532
|
},
|
|
1516
1533
|
socketConnect: function socketConnect() {
|
|
1517
1534
|
this.sendPreLogin();
|
|
1518
|
-
|
|
1535
|
+
this.transitionTo(this.STATE.SENT_PRELOGIN);
|
|
1519
1536
|
}
|
|
1520
1537
|
}
|
|
1521
1538
|
},
|
|
1522
1539
|
SENT_PRELOGIN: {
|
|
1523
1540
|
name: 'SentPrelogin',
|
|
1524
1541
|
enter: function enter() {
|
|
1525
|
-
|
|
1542
|
+
this.emptyMessageBuffer();
|
|
1526
1543
|
},
|
|
1527
1544
|
events: {
|
|
1528
1545
|
socketError: function socketError() {
|
|
1529
|
-
|
|
1546
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1530
1547
|
},
|
|
1531
1548
|
connectTimeout: function connectTimeout() {
|
|
1532
|
-
|
|
1549
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1533
1550
|
},
|
|
1534
1551
|
data: function data(_data) {
|
|
1535
|
-
|
|
1552
|
+
this.addToMessageBuffer(_data);
|
|
1536
1553
|
},
|
|
1537
1554
|
message: function message() {
|
|
1538
|
-
|
|
1555
|
+
this.processPreLoginResponse();
|
|
1539
1556
|
},
|
|
1540
1557
|
noTls: function noTls() {
|
|
1541
1558
|
var _this12 = this;
|
|
1542
1559
|
|
|
1543
1560
|
this.sendLogin7Packet(function () {
|
|
1544
1561
|
if (_this12.config.domain) {
|
|
1545
|
-
|
|
1562
|
+
_this12.transitionTo(_this12.STATE.SENT_LOGIN7_WITH_NTLM);
|
|
1546
1563
|
} else {
|
|
1547
|
-
|
|
1564
|
+
_this12.transitionTo(_this12.STATE.SENT_LOGIN7_WITH_STANDARD_LOGIN);
|
|
1548
1565
|
}
|
|
1549
1566
|
});
|
|
1550
1567
|
},
|
|
1551
1568
|
tls: function tls() {
|
|
1552
1569
|
this.messageIo.startTls(this.config.options.cryptoCredentialsDetails, this.config.server, this.config.options.trustServerCertificate);
|
|
1553
|
-
|
|
1570
|
+
this.transitionTo(this.STATE.SENT_TLSSSLNEGOTIATION);
|
|
1554
1571
|
}
|
|
1555
1572
|
}
|
|
1556
1573
|
},
|
|
1557
1574
|
REROUTING: {
|
|
1558
1575
|
name: 'ReRouting',
|
|
1559
1576
|
enter: function enter() {
|
|
1560
|
-
|
|
1577
|
+
this.cleanupConnection(this.cleanupTypeEnum.REDIRECT);
|
|
1561
1578
|
},
|
|
1562
1579
|
events: {
|
|
1563
1580
|
message: function message() {},
|
|
1564
1581
|
socketError: function socketError() {
|
|
1565
|
-
|
|
1582
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1566
1583
|
},
|
|
1567
1584
|
connectTimeout: function connectTimeout() {
|
|
1568
|
-
|
|
1585
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1569
1586
|
},
|
|
1570
1587
|
reconnect: function reconnect() {
|
|
1571
|
-
|
|
1588
|
+
this.transitionTo(this.STATE.CONNECTING);
|
|
1572
1589
|
}
|
|
1573
1590
|
}
|
|
1574
1591
|
},
|
|
@@ -1576,15 +1593,15 @@ Connection.prototype.STATE = {
|
|
|
1576
1593
|
name: 'TRANSIENT_FAILURE_RETRY',
|
|
1577
1594
|
enter: function enter() {
|
|
1578
1595
|
this.curTransientRetryCount++;
|
|
1579
|
-
|
|
1596
|
+
this.cleanupConnection(this.cleanupTypeEnum.RETRY);
|
|
1580
1597
|
},
|
|
1581
1598
|
events: {
|
|
1582
1599
|
message: function message() {},
|
|
1583
1600
|
socketError: function socketError() {
|
|
1584
|
-
|
|
1601
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1585
1602
|
},
|
|
1586
1603
|
connectTimeout: function connectTimeout() {
|
|
1587
|
-
|
|
1604
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1588
1605
|
},
|
|
1589
1606
|
retry: function retry() {
|
|
1590
1607
|
this.createRetryTimer();
|
|
@@ -1595,13 +1612,13 @@ Connection.prototype.STATE = {
|
|
|
1595
1612
|
name: 'SentTLSSSLNegotiation',
|
|
1596
1613
|
events: {
|
|
1597
1614
|
socketError: function socketError() {
|
|
1598
|
-
|
|
1615
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1599
1616
|
},
|
|
1600
1617
|
connectTimeout: function connectTimeout() {
|
|
1601
|
-
|
|
1618
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1602
1619
|
},
|
|
1603
1620
|
data: function data(_data2) {
|
|
1604
|
-
|
|
1621
|
+
this.messageIo.tlsHandshakeData(_data2);
|
|
1605
1622
|
},
|
|
1606
1623
|
message: function message() {
|
|
1607
1624
|
var _this13 = this;
|
|
@@ -1609,9 +1626,9 @@ Connection.prototype.STATE = {
|
|
|
1609
1626
|
if (this.messageIo.tlsNegotiationComplete) {
|
|
1610
1627
|
this.sendLogin7Packet(function () {
|
|
1611
1628
|
if (_this13.config.domain) {
|
|
1612
|
-
|
|
1629
|
+
_this13.transitionTo(_this13.STATE.SENT_LOGIN7_WITH_NTLM);
|
|
1613
1630
|
} else {
|
|
1614
|
-
|
|
1631
|
+
_this13.transitionTo(_this13.STATE.SENT_LOGIN7_WITH_STANDARD_LOGIN);
|
|
1615
1632
|
}
|
|
1616
1633
|
});
|
|
1617
1634
|
}
|
|
@@ -1622,25 +1639,25 @@ Connection.prototype.STATE = {
|
|
|
1622
1639
|
name: 'SentLogin7WithStandardLogin',
|
|
1623
1640
|
events: {
|
|
1624
1641
|
socketError: function socketError() {
|
|
1625
|
-
|
|
1642
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1626
1643
|
},
|
|
1627
1644
|
connectTimeout: function connectTimeout() {
|
|
1628
|
-
|
|
1645
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1629
1646
|
},
|
|
1630
1647
|
data: function data(_data3) {
|
|
1631
|
-
|
|
1648
|
+
this.sendDataToTokenStreamParser(_data3);
|
|
1632
1649
|
},
|
|
1633
1650
|
loggedIn: function loggedIn() {
|
|
1634
|
-
|
|
1651
|
+
this.transitionTo(this.STATE.LOGGED_IN_SENDING_INITIAL_SQL);
|
|
1635
1652
|
},
|
|
1636
1653
|
routingChange: function routingChange() {
|
|
1637
|
-
|
|
1654
|
+
this.transitionTo(this.STATE.REROUTING);
|
|
1638
1655
|
},
|
|
1639
1656
|
loginFailed: function loginFailed() {
|
|
1640
|
-
|
|
1657
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1641
1658
|
},
|
|
1642
1659
|
message: function message() {
|
|
1643
|
-
|
|
1660
|
+
this.processLogin7Response();
|
|
1644
1661
|
}
|
|
1645
1662
|
}
|
|
1646
1663
|
},
|
|
@@ -1648,22 +1665,22 @@ Connection.prototype.STATE = {
|
|
|
1648
1665
|
name: 'SentLogin7WithNTLMLogin',
|
|
1649
1666
|
events: {
|
|
1650
1667
|
socketError: function socketError() {
|
|
1651
|
-
|
|
1668
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1652
1669
|
},
|
|
1653
1670
|
connectTimeout: function connectTimeout() {
|
|
1654
|
-
|
|
1671
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1655
1672
|
},
|
|
1656
1673
|
data: function data(_data4) {
|
|
1657
|
-
|
|
1674
|
+
this.sendDataToTokenStreamParser(_data4);
|
|
1658
1675
|
},
|
|
1659
1676
|
receivedChallenge: function receivedChallenge() {
|
|
1660
|
-
|
|
1677
|
+
this.sendNTLMResponsePacket();
|
|
1661
1678
|
},
|
|
1662
1679
|
loginFailed: function loginFailed() {
|
|
1663
|
-
|
|
1680
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1664
1681
|
},
|
|
1665
1682
|
message: function message() {
|
|
1666
|
-
|
|
1683
|
+
this.processLogin7NTLMResponse();
|
|
1667
1684
|
}
|
|
1668
1685
|
}
|
|
1669
1686
|
},
|
|
@@ -1671,43 +1688,43 @@ Connection.prototype.STATE = {
|
|
|
1671
1688
|
name: 'SentNTLMResponse',
|
|
1672
1689
|
events: {
|
|
1673
1690
|
socketError: function socketError() {
|
|
1674
|
-
|
|
1691
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1675
1692
|
},
|
|
1676
1693
|
connectTimeout: function connectTimeout() {
|
|
1677
|
-
|
|
1694
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1678
1695
|
},
|
|
1679
1696
|
data: function data(_data5) {
|
|
1680
|
-
|
|
1697
|
+
this.sendDataToTokenStreamParser(_data5);
|
|
1681
1698
|
},
|
|
1682
1699
|
loggedIn: function loggedIn() {
|
|
1683
|
-
|
|
1700
|
+
this.transitionTo(this.STATE.LOGGED_IN_SENDING_INITIAL_SQL);
|
|
1684
1701
|
},
|
|
1685
1702
|
loginFailed: function loginFailed() {
|
|
1686
|
-
|
|
1703
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1687
1704
|
},
|
|
1688
1705
|
routingChange: function routingChange() {
|
|
1689
|
-
|
|
1706
|
+
this.transitionTo(this.STATE.REROUTING);
|
|
1690
1707
|
},
|
|
1691
1708
|
message: function message() {
|
|
1692
|
-
|
|
1709
|
+
this.processLogin7NTLMAck();
|
|
1693
1710
|
}
|
|
1694
1711
|
}
|
|
1695
1712
|
},
|
|
1696
1713
|
LOGGED_IN_SENDING_INITIAL_SQL: {
|
|
1697
1714
|
name: 'LoggedInSendingInitialSql',
|
|
1698
1715
|
enter: function enter() {
|
|
1699
|
-
|
|
1716
|
+
this.sendInitialSql();
|
|
1700
1717
|
},
|
|
1701
1718
|
events: {
|
|
1702
1719
|
connectTimeout: function connectTimeout() {
|
|
1703
|
-
|
|
1720
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1704
1721
|
},
|
|
1705
1722
|
data: function data(_data6) {
|
|
1706
|
-
|
|
1723
|
+
this.sendDataToTokenStreamParser(_data6);
|
|
1707
1724
|
},
|
|
1708
1725
|
message: function message() {
|
|
1709
1726
|
this.transitionTo(this.STATE.LOGGED_IN);
|
|
1710
|
-
|
|
1727
|
+
this.processedInitialSql();
|
|
1711
1728
|
}
|
|
1712
1729
|
}
|
|
1713
1730
|
},
|
|
@@ -1715,7 +1732,7 @@ Connection.prototype.STATE = {
|
|
|
1715
1732
|
name: 'LoggedIn',
|
|
1716
1733
|
events: {
|
|
1717
1734
|
socketError: function socketError() {
|
|
1718
|
-
|
|
1735
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1719
1736
|
}
|
|
1720
1737
|
}
|
|
1721
1738
|
},
|
|
@@ -1733,7 +1750,7 @@ Connection.prototype.STATE = {
|
|
|
1733
1750
|
var sqlRequest = this.request;
|
|
1734
1751
|
this.request = undefined;
|
|
1735
1752
|
sqlRequest.callback(err);
|
|
1736
|
-
|
|
1753
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1737
1754
|
},
|
|
1738
1755
|
data: function data(_data7) {
|
|
1739
1756
|
this.clearRequestTimer(); // request timer is stopped on first data package
|
|
@@ -1748,7 +1765,7 @@ Connection.prototype.STATE = {
|
|
|
1748
1765
|
// We have to channel the 'message' (EOM) event through the token stream
|
|
1749
1766
|
// parser transform, to keep it in line with the flow of the tokens, when
|
|
1750
1767
|
// the incoming data flow is paused and resumed.
|
|
1751
|
-
|
|
1768
|
+
this.tokenStreamParser.addEndOfMessageMarker();
|
|
1752
1769
|
},
|
|
1753
1770
|
endOfMessageMarkerReceived: function endOfMessageMarkerReceived() {
|
|
1754
1771
|
this.transitionTo(this.STATE.LOGGED_IN);
|
|
@@ -1757,24 +1774,24 @@ Connection.prototype.STATE = {
|
|
|
1757
1774
|
if (this.config.options.tdsVersion < '7_2' && sqlRequest.error && this.isSqlBatch) {
|
|
1758
1775
|
this.inTransaction = false;
|
|
1759
1776
|
}
|
|
1760
|
-
|
|
1777
|
+
sqlRequest.callback(sqlRequest.error, sqlRequest.rowCount, sqlRequest.rows);
|
|
1761
1778
|
}
|
|
1762
1779
|
}
|
|
1763
1780
|
},
|
|
1764
1781
|
SENT_ATTENTION: {
|
|
1765
1782
|
name: 'SentAttention',
|
|
1766
1783
|
enter: function enter() {
|
|
1767
|
-
|
|
1784
|
+
this.attentionReceived = false;
|
|
1768
1785
|
},
|
|
1769
1786
|
events: {
|
|
1770
1787
|
socketError: function socketError() {
|
|
1771
|
-
|
|
1788
|
+
this.transitionTo(this.STATE.FINAL);
|
|
1772
1789
|
},
|
|
1773
1790
|
data: function data(_data8) {
|
|
1774
|
-
|
|
1791
|
+
this.sendDataToTokenStreamParser(_data8);
|
|
1775
1792
|
},
|
|
1776
1793
|
attention: function attention() {
|
|
1777
|
-
|
|
1794
|
+
this.attentionReceived = true;
|
|
1778
1795
|
},
|
|
1779
1796
|
message: function message() {
|
|
1780
1797
|
// 3.2.5.7 Sent Attention State
|
|
@@ -1784,10 +1801,10 @@ Connection.prototype.STATE = {
|
|
|
1784
1801
|
this.request = undefined;
|
|
1785
1802
|
this.transitionTo(this.STATE.LOGGED_IN);
|
|
1786
1803
|
if (sqlRequest.canceled) {
|
|
1787
|
-
|
|
1804
|
+
sqlRequest.callback(RequestError('Canceled.', 'ECANCEL'));
|
|
1788
1805
|
} else {
|
|
1789
1806
|
var message = 'Timeout: Request failed to complete in ' + this.config.options.requestTimeout + 'ms';
|
|
1790
|
-
|
|
1807
|
+
sqlRequest.callback(RequestError(message, 'ETIMEOUT'));
|
|
1791
1808
|
}
|
|
1792
1809
|
}
|
|
1793
1810
|
}
|
|
@@ -1796,7 +1813,7 @@ Connection.prototype.STATE = {
|
|
|
1796
1813
|
FINAL: {
|
|
1797
1814
|
name: 'Final',
|
|
1798
1815
|
enter: function enter() {
|
|
1799
|
-
|
|
1816
|
+
this.cleanupConnection(this.cleanupTypeEnum.NORMAL);
|
|
1800
1817
|
},
|
|
1801
1818
|
events: {
|
|
1802
1819
|
loginFailed: function loginFailed() {
|