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