@@ -15,22 +15,24 @@ describe('Parsing a RETURNVALUE token', function() {
15
15
16
16
describe ( 'in TDS 7.0 mode' , function ( ) {
17
17
18
- let reader , data , paramOrdinal , paramName , status , userType , typeid , dataLength , value , offset , tempBuff ;
18
+ let reader , data , paramOrdinal , paramName , status , userType , flag , typeid , dataLength , value , offset , tempOffset , tempBuff ;
19
19
20
20
before ( function ( ) {
21
21
paramOrdinal = 1 ;
22
22
paramName = '@count' ;
23
23
status = 1 ;
24
24
userType = 0 ;
25
+ flag = 0 ;
25
26
typeid = 0x26 ;
26
27
value = 4 ;
27
- offset = 0 ;
28
+ tempOffset = 0 ;
28
29
tempBuff = Buffer . alloc ( 21 ) ;
29
30
buildDataBuffer ( ) ;
30
31
} ) ;
31
32
32
33
beforeEach ( function ( ) {
33
34
reader = new Reader ( 0x07000000 ) ;
35
+ offset = tempOffset ;
34
36
} ) ;
35
37
36
38
function addListners ( done , token ) {
@@ -51,18 +53,17 @@ describe('Parsing a RETURNVALUE token', function() {
51
53
}
52
54
53
55
function buildDataBuffer ( ) {
54
- tempBuff . writeUInt8 ( 0xAC , offset ++ ) ;
55
- tempBuff . writeUInt16LE ( paramOrdinal , offset ) ;
56
- offset += 2 ;
57
- tempBuff . writeUInt8 ( paramName . length , offset ++ ) ;
58
- tempBuff . write ( paramName , offset , paramName . length * 2 , 'ucs2' ) ;
59
- offset += paramName . length * 2 ;
60
- tempBuff . writeUInt8 ( status , offset ++ ) ;
61
- tempBuff . writeUInt16LE ( userType , offset ) ;
62
- offset += 2 ;
63
- // Flag
64
- tempBuff . writeUInt16LE ( 0 , offset ) ;
65
- offset += 2 ;
56
+ tempBuff . writeUInt8 ( 0xAC , tempOffset ++ ) ;
57
+ tempBuff . writeUInt16LE ( paramOrdinal , tempOffset ) ;
58
+ tempOffset += 2 ;
59
+ tempBuff . writeUInt8 ( paramName . length , tempOffset ++ ) ;
60
+ tempBuff . write ( paramName , tempOffset , paramName . length * 2 , 'ucs2' ) ;
61
+ tempOffset += paramName . length * 2 ;
62
+ tempBuff . writeUInt8 ( status , tempOffset ++ ) ;
63
+ tempBuff . writeUInt16LE ( userType , tempOffset ) ;
64
+ tempOffset += 2 ;
65
+ tempBuff . writeUInt16LE ( flag , tempOffset ) ;
66
+ tempOffset += 2 ;
66
67
}
67
68
68
69
it ( 'should parse the INTNTYPE(Int) token correctly' , function ( done ) {
@@ -82,19 +83,43 @@ describe('Parsing a RETURNVALUE token', function() {
82
83
addListners ( done , token ) ;
83
84
reader . end ( data ) ;
84
85
} ) ;
86
+
87
+ it ( 'should throw exception on receiving non-zero flag' , function ( done ) {
88
+ dataLength = 4 ;
89
+
90
+ data = Buffer . alloc ( 28 ) ;
91
+ tempBuff . copy ( data , 0 , 0 , offset - 2 ) ;
92
+
93
+ // write non-zero flag
94
+ data . writeUInt16LE ( 56 , offset - 2 ) ;
95
+
96
+ // TYPE_INFO
97
+ data . writeUInt8 ( typeid , offset ++ ) ;
98
+ data . writeUInt8 ( dataLength , offset ++ ) ;
99
+
100
+ // TYPE_VARBYTE
101
+ data . writeUInt8 ( dataLength , offset ++ ) ;
102
+ data . writeUInt32LE ( value , offset ) ;
103
+ const token = { } ;
104
+
105
+ addListners ( done , token ) ;
106
+ assert . throw ( ( ) => reader . end ( data ) , Error , 'Unknown flags in RETURNVALUE_TOKEN' ) ;
107
+ done ( ) ;
108
+ } ) ;
85
109
} ) ;
86
110
87
111
describe ( 'in TDS 7.2 mode' , function ( ) {
88
112
89
113
describe ( 'test INTNTYPE' , function ( ) {
90
114
91
- let reader , data , paramOrdinal , paramName , status , userType , typeid , dataLength , value , offset , tempBuff , tempOffset ;
115
+ let reader , data , paramOrdinal , paramName , status , userType , flag , typeid , dataLength , value , offset , tempBuff , tempOffset ;
92
116
93
117
before ( function ( ) {
94
118
paramOrdinal = 1 ;
95
119
paramName = '@count' ;
96
120
status = 1 ;
97
121
userType = 0 ;
122
+ flag = 0 ;
98
123
typeid = 0x26 ;
99
124
value = 4 ;
100
125
tempOffset = 0 ;
@@ -104,6 +129,7 @@ describe('Parsing a RETURNVALUE token', function() {
104
129
105
130
beforeEach ( function ( ) {
106
131
reader = new Reader ( 0x72090002 ) ;
132
+ offset = tempOffset ;
107
133
} ) ;
108
134
109
135
function addListners ( done , token ) {
@@ -133,14 +159,12 @@ describe('Parsing a RETURNVALUE token', function() {
133
159
tempBuff . writeUInt8 ( status , tempOffset ++ ) ;
134
160
tempBuff . writeUInt32LE ( userType , tempOffset ) ;
135
161
tempOffset += 4 ;
136
- // Flag
137
- tempBuff . writeUInt16LE ( 0 , tempOffset ) ;
162
+ tempBuff . writeUInt16LE ( flag , tempOffset ) ;
138
163
tempOffset += 2 ;
139
164
}
140
165
141
166
it ( 'should parse the INTNTYPE(Tinyint) token correctly' , function ( done ) {
142
167
dataLength = 1 ;
143
- offset = tempOffset ;
144
168
145
169
data = Buffer . alloc ( 27 ) ;
146
170
tempBuff . copy ( data ) ;
@@ -159,7 +183,6 @@ describe('Parsing a RETURNVALUE token', function() {
159
183
160
184
it ( 'should parse the INTNTYPE(smallint) token correctly' , function ( done ) {
161
185
dataLength = 2 ;
162
- offset = tempOffset ;
163
186
164
187
data = Buffer . alloc ( 28 ) ;
165
188
tempBuff . copy ( data ) ;
@@ -179,7 +202,6 @@ describe('Parsing a RETURNVALUE token', function() {
179
202
180
203
it ( 'should parse the INTNTYPE(Int) token correctly' , function ( done ) {
181
204
dataLength = 4 ;
182
- offset = tempOffset ;
183
205
184
206
data = Buffer . alloc ( 30 ) ;
185
207
tempBuff . copy ( data ) ;
@@ -198,7 +220,6 @@ describe('Parsing a RETURNVALUE token', function() {
198
220
199
221
it ( 'should parse the INTNTYPE(Bigint) token correctly' , function ( done ) {
200
222
dataLength = 8 ;
201
- offset = tempOffset ;
202
223
203
224
data = Buffer . alloc ( 34 ) ;
204
225
tempBuff . copy ( data ) ;
@@ -220,7 +241,6 @@ describe('Parsing a RETURNVALUE token', function() {
220
241
it ( 'should parse the INTNTYPE(null) token correctly' , function ( done ) {
221
242
dataLength = 8 ;
222
243
value = null ;
223
- offset = tempOffset ;
224
244
225
245
data = Buffer . alloc ( 26 ) ;
226
246
tempBuff . copy ( data ) ;
@@ -253,7 +273,7 @@ describe('Parsing a RETURNVALUE token', function() {
253
273
254
274
beforeEach ( function ( ) {
255
275
reader = new Reader ( 0x72090002 ) ;
256
-
276
+ offset = tempOffset ;
257
277
} ) ;
258
278
259
279
@@ -301,7 +321,6 @@ describe('Parsing a RETURNVALUE token', function() {
301
321
it ( 'should parse the NULLTYPE token correctly' , function ( done ) {
302
322
typeid = 0x1F ;
303
323
value = null ;
304
- offset = tempOffset ;
305
324
306
325
data = Buffer . alloc ( 24 ) ;
307
326
tempBuff . copy ( data ) ;
@@ -318,7 +337,6 @@ describe('Parsing a RETURNVALUE token', function() {
318
337
it ( 'should parse the INT1TYPE/TintInt token correctly' , function ( done ) {
319
338
typeid = 0x30 ;
320
339
value = 255 ;
321
- offset = tempOffset ;
322
340
323
341
data = Buffer . alloc ( 25 ) ;
324
342
tempBuff . copy ( data ) ;
@@ -337,7 +355,6 @@ describe('Parsing a RETURNVALUE token', function() {
337
355
it ( 'should parse the BITTYPE token correctly' , function ( done ) {
338
356
typeid = 0x32 ;
339
357
value = false ;
340
- offset = tempOffset ;
341
358
342
359
data = Buffer . alloc ( 25 ) ;
343
360
tempBuff . copy ( data ) ;
@@ -356,7 +373,6 @@ describe('Parsing a RETURNVALUE token', function() {
356
373
it ( 'should parse the INT2TYPE/SmallInt token correctly' , function ( done ) {
357
374
typeid = 0x34 ;
358
375
value = 32767 ;
359
- offset = tempOffset ;
360
376
361
377
data = Buffer . alloc ( 26 ) ;
362
378
tempBuff . copy ( data ) ;
@@ -375,7 +391,6 @@ describe('Parsing a RETURNVALUE token', function() {
375
391
it ( 'should parse the INT4TYPE/Int token correctly' , function ( done ) {
376
392
typeid = 0x38 ;
377
393
value = - 2147483648 ;
378
- offset = tempOffset ;
379
394
380
395
data = Buffer . alloc ( 28 ) ;
381
396
tempBuff . copy ( data ) ;
@@ -395,7 +410,6 @@ describe('Parsing a RETURNVALUE token', function() {
395
410
typeid = 0x7F ;
396
411
// value = -2147483648;
397
412
value = 147483648 ;
398
- offset = tempOffset ;
399
413
400
414
data = Buffer . alloc ( 32 ) ;
401
415
tempBuff . copy ( data ) ;
@@ -420,7 +434,6 @@ describe('Parsing a RETURNVALUE token', function() {
420
434
const days = 43225 ; // days since 1900-01-01
421
435
const minutes = 763 ;
422
436
value = new Date ( '2018-05-07T12:43:00.000Z' ) ;
423
- offset = tempOffset ;
424
437
425
438
data = Buffer . alloc ( 28 ) ;
426
439
tempBuff . copy ( data ) ;
@@ -445,7 +458,6 @@ describe('Parsing a RETURNVALUE token', function() {
445
458
const days = 43225 ;
446
459
const minutes = 763 ;
447
460
value = new Date ( '2018-05-07T12:43:00.000' ) ;
448
- offset = tempOffset ;
449
461
450
462
data = Buffer . alloc ( 28 ) ;
451
463
tempBuff . copy ( data ) ;
@@ -466,7 +478,6 @@ describe('Parsing a RETURNVALUE token', function() {
466
478
it ( 'should parse the FLT4TYPE/Real token correctly' , function ( done ) {
467
479
typeid = 0x3B ;
468
480
value = 9654.2529296875 ;
469
- offset = tempOffset ;
470
481
471
482
data = Buffer . alloc ( 28 ) ;
472
483
tempBuff . copy ( data ) ;
@@ -485,7 +496,6 @@ describe('Parsing a RETURNVALUE token', function() {
485
496
it ( 'should parse the FLT8TYPE/Float token correctly' , function ( done ) {
486
497
typeid = 0x3E ;
487
498
value = 9654.2546456567565767644 ;
488
- offset = tempOffset ;
489
499
490
500
data = Buffer . alloc ( 32 ) ;
491
501
tempBuff . copy ( data ) ;
@@ -504,7 +514,6 @@ describe('Parsing a RETURNVALUE token', function() {
504
514
it ( 'should parse the MONEYTYPE/Money token correctly' , function ( done ) {
505
515
typeid = 0x3C ;
506
516
value = 922337203.5807 ;
507
- offset = tempOffset ;
508
517
509
518
const TDS_value = value * 10000 ;
510
519
data = Buffer . alloc ( 32 ) ;
@@ -525,7 +534,6 @@ describe('Parsing a RETURNVALUE token', function() {
525
534
it ( 'should parse the MONEY4TYPE/SmallMoney token correctly' , function ( done ) {
526
535
typeid = 0x7A ;
527
536
value = - 214748.3647 ;
528
- offset = tempOffset ;
529
537
530
538
const TDS_value = value * 10000 ;
531
539
data = Buffer . alloc ( 28 ) ;
@@ -545,7 +553,6 @@ describe('Parsing a RETURNVALUE token', function() {
545
553
it ( 'should parse the DATETIMETYPE/DateTime token correctly' , function ( done ) {
546
554
reader . options = { } ;
547
555
reader . options . useUTC = true ;
548
- offset = tempOffset ;
549
556
550
557
typeid = 0x3D ;
551
558
value = new Date ( '2004-05-23T14:25:10.487Z' ) ;
0 commit comments