-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathdatatypes.test.js
More file actions
executable file
·1099 lines (985 loc) · 37.4 KB
/
Copy pathdatatypes.test.js
File metadata and controls
executable file
·1099 lines (985 loc) · 37.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ---------------------------------------------------------------------------------------------------------------------------------
// File: datatypes.js
// Contents: test suite for verifying the driver can use SQL Server Datatypes
//
// Copyright Microsoft Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ---------------------------------------------------------------------------------------------------------------------------------`
/* globals describe it */
'use strict'
import { createRequire } from 'module'
import chaiAsPromised from 'chai-as-promised'
const require = createRequire(import.meta.url)
const { TestEnv } = require('./env/test-env')
const env = new TestEnv()
const chai = require('chai')
chai.use(chaiAsPromised)
const expect = chai.expect
const assert = chai.assert
// Enable trace-level logging for debugging test failures
const sql = require('../lib/sql')
const { configureTestLogging } = require('./common/logging-helper')
// Configure logging based on environment variables
// By default, tests run silently. To enable logging:
// - MSNODESQLV8_TEST_VERBOSE=true npm test (for full trace logging)
// - MSNODESQLV8_TEST_LOG_LEVEL=DEBUG MSNODESQLV8_TEST_LOG_CONSOLE=true npm test
// - MSNODESQLV8_TEST_LOG_LEVEL=INFO MSNODESQLV8_TEST_LOG_FILE=/tmp/test.log npm test
configureTestLogging(sql)
describe('datatypes', function () {
const tablename = 'types_table'
const testname = 'not set yet'
const driver = 'SQL Server Native Client 11.0'
this.timeout(20000)
// ========================================
// TEST SETUP AND TEARDOWN
// ========================================
this.beforeEach(async function () {
sql.logger.info('Starting test setup', 'params.test.beforeEach')
await env.open()
sql.logger.info('Test environment opened successfully', 'params.test.beforeEach')
})
this.afterEach(async function () {
sql.logger.info('Starting test cleanup', 'params.test.afterEach')
await env.close()
sql.logger.info('Test environment closed successfully', 'params.test.afterEach')
})
it('write / read an image column', async function handler () {
const testcolumntype = ' Image'
const testcolumnname = 'col1'
await env.commonTestFnPromises.create(env.theConnection, tablename, testcolumnname, testcolumntype)
const binaryBuffer = await env.readAsBinary('SampleJPGImage_50kbmb.jpg')
const insertSql = `insert into ${tablename} (${testcolumnname} ) values ( ? )`
const promises = env.theConnection.promises
await promises.query(insertSql, [env.sql.LongVarBinary(binaryBuffer)])
const selectSql = `select ${testcolumnname} from ${tablename}`
const r = await promises.query(selectSql)
expect(r.first[0].col1).to.deep.equal(binaryBuffer)
})
it('test 001 - verify functionality of data type \'smalldatetime\', fetch as date', async function handler () {
// var testcolumnsize = 16
const testcolumntype = ' smalldatetime'
// var testcolumnclienttype = 'date'
const testcolumnname = 'col2'
const rowWithNullData = 1
// test date = 1955-12-13 12:43:00
const year = 1955
const month = 12
const day = 13
const hour = 12
const minute = 43
const second = 0
const nanosecond = 0
const testdata2Expected = `${year}-${month}-${day} ${hour}:${minute}:${second}`
const testdata2TsqlInsert = `'${testdata2Expected}'`
// Month in JS is 0-based, so expected will be month minus 1
const jsDateExpected = new Date(year, month - 1, day, hour - env.commonTestFns.getTimezoneOffsetInHours(year, month, day), minute, second, nanosecond)
const proxy = env.makeTestFnProxy(tablename, testcolumnname)
proxy.params.jsDateExpected = jsDateExpected
proxy.params.rowWithNullData = rowWithNullData
proxy.params.testcolumntype = testcolumntype
proxy.params.testdata2TsqlInsert = testdata2TsqlInsert
await proxy.testerDatetime()
})
it('test 002 - verify functionality of data type \'datetime\', fetch as date', async function handler () {
// var testcolumnsize = 23
const testcolumntype = ' datetime'
// var testcolumnclienttype = 'date'
const testcolumnname = 'col2'
const rowWithNullData = 2
// test date = 2007-05-08 12:35:29.123
const year = 2007
const month = 5
const day = 8
const hour = 12
const minute = 35
const second = 29.123
const nanosecond = 0
const testdata2Expected = `${year}-${month}-${day} ${hour}:${minute}:${second}`
const testdata2TsqlInsert = `'${testdata2Expected}'`
// Month in JS is 0-based, so expected will be month minus 1
const jsDateExpected = new Date(year, month - 1, day, hour - env.commonTestFns.getTimezoneOffsetInHours(year, month, day), minute, second, nanosecond)
const proxy = env.makeTestFnProxy(tablename, testcolumnname)
await proxy.create(testcolumntype)
await proxy.insert(testdata2TsqlInsert)
await proxy.insert(null)
await proxy.verifyData_Datetime(rowWithNullData, jsDateExpected, testname)
}) // end of it(
async function timeTest (testdatetimescale) {
const testcolumntype = ` time(${testdatetimescale})`
// var testcolumnclienttype = 'date'
const testcolumnname = 'col2'
const testdata1 = null
const rowWithNullData = 1
// test date = <default date> 12:10:05.1234567
const year = 1970
const month = 1
const day = 1
const hour = 12
const minute = 10
const second = 5
const nanosecond = 0
// Month in JS is 0-based, so expected will be month minus 1
const jsDateExpected = new Date(year, month - 1, day, hour - env.commonTestFns.getTimezoneOffsetInHours(year, month, day), minute, second, nanosecond)
const testdata2Expected = '12:10:05.1234567'
const testdata2TsqlInsert = `'${testdata2Expected}'`
const proxy = env.makeTestFnProxy(tablename, testcolumnname)
await proxy.create(testcolumntype)
await proxy.insert(testdata1)
await proxy.insert(testdata2TsqlInsert)
await proxy.verifyData_Datetime(rowWithNullData, jsDateExpected, testname)
}
it('test 003_a - insert valid data into time(7) via TSQL, fetch as date', async function handler () {
// var testcolumnsize = 16
await timeTest(7)
}) // end of it()
it('test 003_b - insert valid data into time(0) via TSQL, fetch as date', async function handler () {
// var testcolumnsize = 16
await timeTest(0)
}) // end of it()
async function t04 (testdatetimescale, second) {
const testcolumntype = ` datetime2(${testdatetimescale})`
// var testcolumnclienttype = 'date'
const testcolumnname = 'col2'
const testdata1 = null
const rowWithNullData = 1
// test date = 2001-04-10 10:12:59.1234567
const year = 2001
const month = 4
const day = 10
const hour = 10
const minute = 12
const nanosecond = 0
// Month in JS is 0-based, so expected will be month minus 1
const jsDateExpected = new Date(year, month - 1, day, hour - env.commonTestFns.getTimezoneOffsetInHours(year, month, day), minute, second, nanosecond)
const testdata2Expected = '2001-04-10 10:12:59.1234567'
const testdata2TsqlInsert = `'${testdata2Expected}'`
const proxy = env.makeTestFnProxy(tablename, testcolumnname)
await proxy.create(testcolumntype)
await proxy.insert(testdata1)
await proxy.insert(testdata2TsqlInsert)
await proxy.verifyData_Datetime(rowWithNullData, jsDateExpected, testname)
}
it('test 004_a - insert valid data into datetime2(7) via TSQL, fetch as date', async function handler () {
// var testcolumnsize = 27
await t04(7, 59.1234567)
})
it('test 004_b - insert valid data into datetime2(0) via TSQL, fetch as date', async function handler () {
// var testcolumnsize = 19
await t04(0, 59)
}) // end of it()
async function t05 (testdatetimescale, second) {
const testcolumntype = ` datetimeoffset(${testdatetimescale})`
// var testcolumnclienttype = 'date'
const testcolumnname = 'col2'
const testdata1 = null
const rowWithNullData = 1
// test date = 2001-04-10 10:12:59.1234567 +13:30
const year = 2001
const month = 4
const day = 10
const hour = 10
const minute = 12
const nanosecond = 0
const offsetHours = 13
const offsetMinutes = 30
// Month in JS is 0-based, so expected will be month minus 1
const jsDateExpected = new Date(year, month - 1, day, hour, minute, second, nanosecond)
jsDateExpected.setHours(jsDateExpected.getHours() - env.commonTestFns.getTimezoneOffsetInHours(year, month, day))
jsDateExpected.setHours(jsDateExpected.getHours() - offsetHours)
jsDateExpected.setMinutes(jsDateExpected.getMinutes() - offsetMinutes)
const testdata2Expected = `2001-04-10 10:12:59.1234567 +${offsetHours}:${offsetMinutes}`
const testdata2TsqlInsert = `'${testdata2Expected}'`
const proxy = env.makeTestFnProxy(tablename, testcolumnname)
await proxy.create(testcolumntype)
await proxy.insert(testdata1)
await proxy.insert(testdata2TsqlInsert)
await proxy.verifyData_Datetime(rowWithNullData, jsDateExpected, testname)
}
it('test 005_a - insert valid data into datetimeoffset(7) via TSQL, fetch as date', async function handler () {
// var testcolumnsize = 34
await t05(7, 59.1234567)
}) // end of it()
it('test 005_b - insert valid data into datetimeoffset(0) via TSQL, fetch as date', async function handler () {
// var testcolumnsize = 26
await t05(0, 59)
}) // end of it()
it('test 006_a - insert valid data into datetimeoffset(7) via TSQL, fetch as date UTC', async function handler () {
// var testcolumnsize = 34
const testdatetimescale = 7
const testcolumntype = ` datetimeoffset(${testdatetimescale})`
// var testcolumnclienttype = 'date'
const testcolumnname = 'col2'
const testdata1 = null
const rowWithNullData = 1
// test date = 2001-04-10 10:12:59 +13:30
const year = 2001
const month = 4
const day = 10
const hour = 10
const minute = 12
const second = 59
const nanosecond = 0
const offsetHours = 13
const offsetMinutes = 30
// Month in JS is 0-based, so expected will be month minus 1
const jsDateExpected = new Date(Date.UTC(year, month - 1, day, hour, minute, second, nanosecond))
jsDateExpected.setHours(jsDateExpected.getHours() - offsetHours)
jsDateExpected.setMinutes(jsDateExpected.getMinutes() - offsetMinutes)
const testdata2Expected = `2001-04-10 10:12:59.1234567 +${offsetHours}:${offsetMinutes}`
const testdata2TsqlInsert = '\'' + testdata2Expected + '\''
const proxy = env.makeTestFnProxy(tablename, testcolumnname)
await proxy.create(testcolumntype)
await proxy.insert(testdata1)
await proxy.insert(testdata2TsqlInsert)
await proxy.verifyData_Datetime(rowWithNullData, jsDateExpected, testname)
}) // end of it()
it('test 007 - insert valid data into date via TSQL, fetch as date', async function handler () {
// var testcolumnsize = 10
// var testdatetimescale = 0
const testcolumntype = ' date'
// var testcolumnclienttype = 'date'
const testcolumnname = 'col2'
const testdata1 = null
const rowWithNullData = 1
// test date = 2005-12-21
const year = 2005
const month = 12
const day = 21
const hour = 0
const minute = 0
const second = 0
const nanosecond = 0
const testdata2Expected = '2005-12-21'
const testdata2TsqlInsert = `'${testdata2Expected}'`
const jsDateExpected = new Date(year, month - 1, day, hour - env.commonTestFns.getTimezoneOffsetInHours(year, month, day), minute, second, nanosecond)
const proxy = env.makeTestFnProxy(tablename, testcolumnname)
await proxy.create(testcolumntype)
await proxy.insert(testdata1)
await proxy.insert(testdata2TsqlInsert)
await proxy.verifyData_Datetime(rowWithNullData, jsDateExpected, testname)
}) // end of it()
class ParamsTester {
static A100CharacterString = '0234567890123456789022345678903234567890423456789052345678906234567890723456789082345678909234567890'
static A2000CharacterString = ParamsTester.A100CharacterString.repeat(20)
static makeExpected (testParams) {
let nullable = true
if (Object.prototype.hasOwnProperty.call(testParams, 'nullable')) {
nullable = testParams.insert
}
return {
meta: [
{
name: 'id', size: 10, nullable: false, type: 'number', sqlType: 'int identity'
},
{
name: testParams.testcolumnname,
size: testParams.testcolumnsize,
nullable,
type: testParams.testcolumnclienttype,
sqlType: testParams.testcolumnsqltype.trim()
}
],
rows: [
[1, testParams.testdata1],
[2, testParams.testdata2Expected]
]
}
}
static async runTestParams (testParams) {
const expected = ParamsTester.makeExpected(testParams)
const proxy = env.makeTestFnProxy(tablename, testParams.testcolumnname)
await proxy.create(testParams.testcolumntype)
await proxy.insert(testParams.testdata1)
if (testParams.testdata1TsqlInsert) await proxy.insert(testParams.testdata1TsqlInsert)
if (testParams.testdata2TsqlInsert) await proxy.insert(testParams.testdata2TsqlInsert)
await proxy.verifyData(expected, testParams.testname)
}
static inQuotes (s) {
return `'${s}'`
}
static getUniqueIdentifierParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 36,
testcolumntype: ' uniqueidentifier',
testcolumnclienttype: 'text',
testcolumnsqltype: 'uniqueidentifier',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getVarCharMaxParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 0,
testcolumntype: ' varchar(max)',
testcolumnclienttype: 'text',
testcolumnsqltype: 'varchar',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getTextMaxParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
return {
testcolumnsize: colSize,
testcolumntype: ' text',
testcolumnclienttype: 'text',
testcolumnsqltype: 'text',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getTinyIntParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 3,
testcolumntype: ' tinyint',
testcolumnclienttype: 'number',
testcolumnsqltype: 'tinyint',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getSmallIntParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 5,
testcolumntype: ' smallint',
testcolumnclienttype: 'number',
testcolumnsqltype: 'smallint',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getIntParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 10,
testcolumntype: ' int',
testcolumnclienttype: 'number',
testcolumnsqltype: 'int',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getBitParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 1,
testcolumntype: ' bit',
testcolumnclienttype: 'boolean',
testcolumnsqltype: 'bit',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getNCharParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
colSize = colSize || 10
return {
testcolumnsize: colSize,
testcolumntype: ` nchar (${colSize})`,
testcolumnclienttype: 'text',
testcolumnsqltype: 'nchar',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getNVarCharParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
colSize = colSize || 10
return {
testcolumnsize: colSize,
testcolumntype: ` nvarchar (${colSize})`,
testcolumnclienttype: 'text',
testcolumnsqltype: 'nvarchar',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getNTextParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
return {
testcolumnsize: colSize,
testcolumntype: ' ntext',
testcolumnclienttype: 'text',
testcolumnsqltype: 'ntext',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getSysNameParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
return {
testcolumnsize: colSize,
testcolumntype: ' sysname',
testcolumnclienttype: 'text',
testcolumnsqltype: 'nvarchar',
testcolumnname: 'col2',
nullable: false,
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getNVarCharMaxParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 0,
testcolumntype: ' nvarchar (max)',
testcolumnclienttype: 'text',
testcolumnsqltype: 'nvarchar',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getCharParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
colSize = colSize || 10
return {
testcolumnsize: colSize,
testcolumntype: ` char (${colSize})`,
testcolumnclienttype: 'text',
testcolumnsqltype: 'char',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getVarCharParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
colSize = colSize || 10
return {
testcolumnsize: colSize,
testcolumntype: ` varchar (${colSize})`,
testcolumnclienttype: 'text',
testcolumnsqltype: 'varchar',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getBinaryParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
colSize = colSize || 10
return {
testcolumnsize: colSize,
testcolumntype: ` binary (${colSize})`,
testcolumnclienttype: 'binary',
testcolumnsqltype: 'binary',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getVarBinaryParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
colSize = colSize || 10
return {
testcolumnsize: colSize,
testcolumntype: ` varbinary (${colSize})`,
testcolumnclienttype: 'binary',
testcolumnsqltype: 'varbinary',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getImageParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
return {
testcolumnsize: colSize,
testcolumntype: ' image',
testcolumnclienttype: 'binary',
testcolumnsqltype: 'image',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getXmlParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 0,
testcolumntype: ' xml',
testcolumnclienttype: 'text',
testcolumnsqltype: 'xml',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getVarBinaryMaxParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 0,
testcolumntype: 'varbinary (max)',
testcolumnclienttype: 'binary',
testcolumnsqltype: 'varbinary',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getRealParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 24,
testcolumntype: ' real',
testcolumnclienttype: 'number',
testcolumnsqltype: 'real',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getBigIntParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 19,
testcolumntype: ' bigint',
testcolumnclienttype: 'number',
testcolumnsqltype: 'bigint',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getNumericParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize, decPlaces) {
colSize = colSize || 7
decPlaces = decPlaces || 3
return {
testcolumnsize: colSize,
testcolumntype: `numeric (${colSize}, ${decPlaces})`,
testcolumnclienttype: 'number',
testcolumnsqltype: 'numeric',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getFloatParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize) {
colSize = colSize || 53
return {
testcolumnsize: colSize,
testcolumntype: `float (${colSize})`,
testcolumnclienttype: 'number',
testcolumnsqltype: 'float',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getDecimalParams (testdata1, testdata2Expected, testdata2TsqlInsert, colSize, decPlaces) {
colSize = colSize || 7
decPlaces = decPlaces || 3
return {
testcolumnsize: colSize,
testcolumntype: `decimal (${colSize}, ${decPlaces})`,
testcolumnclienttype: 'number',
testcolumnsqltype: 'decimal',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
static getSmallMoneyParams (testdata1, testdata2Expected, testdata2TsqlInsert) {
return {
testcolumnsize: 10,
testcolumntype: ' smallmoney',
testcolumnclienttype: 'number',
testcolumnsqltype: 'smallmoney',
testcolumnname: 'col2',
testdata1,
testdata2Expected,
testdata2TsqlInsert
}
}
}
it('test 008 - insert null into varchar(max) via TSQL, fetch as text', async function handler () {
const s = 'string data row 2'
const testParams = ParamsTester.getVarCharMaxParams(
null,
s,
ParamsTester.inQuotes(s))
await ParamsTester.runTestParams(testParams)
// end of it():
})
// currently, buffer size is 2048 characters, so a 2048 char string should not call 'more' in the OdbcConnection.cpp, but fetch entire result set at once.
it('test 008_bndryCheck_VC - insert 2048 char string into varchar(max) via TSQL, fetch as text', async function handler () {
const A2000CharacterString = ParamsTester.A2000CharacterString
const testdata2Expected = 'AStringWith2048Characters_aaaa5aaa10aaa15aaa20aa' + A2000CharacterString
const testParams = ParamsTester.getVarCharMaxParams(
null,
testdata2Expected,
ParamsTester.inQuotes(testdata2Expected))
await ParamsTester.runTestParams(testParams)
// end of it():
})
// currently, buffer size is 2048 characters, so a 2049 char string should call 'more' in the OdbcConnection.cpp and concatenate to correctly return larger data
it('test 008_bndryCheck_NVC - insert 2049 char string into nvarchar(max) via TSQL, fetch as text', async function handler () {
const A2000CharacterString = ParamsTester.A2000CharacterString
const testdata2Expected = `AStringWith2049Characters_aaaa5aaa10aaa15aaa20aaa${A2000CharacterString}`
const testParams = ParamsTester.getVarCharMaxParams(
null,
testdata2Expected,
ParamsTester.inQuotes(testdata2Expected))
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 009 - verify functionality of data type \'guid\', fetch as text', async function handler () {
const testdata2Expected = '0E984725-C51C-4BF4-9960-E1C80E27ABA0'
const testParams = ParamsTester.getUniqueIdentifierParams(
null,
testdata2Expected,
ParamsTester.inQuotes(testdata2Expected))
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 010 - verify functionality of data type \'tinyint\', fetch as number', async function handler () {
const testdata2Expected = 255
const testParams = ParamsTester.getTinyIntParams(
null,
testdata2Expected,
testdata2Expected)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 011 - verify functionality of data type \'smallint\', fetch as number', async function handler () {
const testdata2Expected = 32767
const testParams = ParamsTester.getSmallIntParams(
null,
testdata2Expected,
testdata2Expected)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 012 - verify functionality of data type \'int\', fetch as number', async function handler () {
const testdata2Expected = -2147483648
const testParams = ParamsTester.getIntParams(
null,
testdata2Expected,
testdata2Expected)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 013 - verify functionality of data type \'bigint\', fetch as number', async function handler () {
const testdata2Expected = -9223372036854775808
const testParams = ParamsTester.getBigIntParams(
null,
testdata2Expected,
testdata2Expected)
if (env.commonTestFns.SKIP_FAILING_HANGING_TEST_CASES) return
await ParamsTester.runTestParams(testParams)
})
it('test 014 - verify functionality of data type \'smallmoney\', fetch as number', async function handler () {
const testdata2Expected = 214748.3647
const testParams = ParamsTester.getSmallMoneyParams(
null,
testdata2Expected,
testdata2Expected)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 015 - verify functionality of data type \'money\', fetch as number', async function handler () {
// var testcolumnsize = 19
const testcolumntype = ' money'
// var testcolumnclienttype = 'number'
const testcolumnname = 'col2'
const testdata1 = null
// eslint-disable-next-line no-loss-of-precision
const testdata2TsqlInsert = -922337203685477.5808
const tsql = 'SELECT * FROM types_table ORDER BY id'
const expectedError = `[Microsoft][${driver}][SQL Server]Arithmetic overflow`
if (env.commonTestFns.SKIP_FAILING_HANGING_TEST_CASES) return
const proxy = env.makeTestFnProxy(tablename, testcolumnname)
await proxy.create(testcolumntype)
await proxy.insert(testdata1)
await proxy.insert(testdata2TsqlInsert)
await proxy.invalidQuery(tsql, expectedError)
// end of it():
})
it('test 016 - verify functionality of data type \'numeric(7,3)\', fetch as number', async function handler () {
const testdata2Expected = 1234.567
const testParams = ParamsTester.getNumericParams(
null,
testdata2Expected,
testdata2Expected, 7, 3)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 017 - verify functionality of data type \'decimal(7,3)\', fetch as number', async function handler () {
const testdata2Expected = 1234.567
const testParams = ParamsTester.getDecimalParams(
null,
testdata2Expected,
testdata2Expected, 7, 3)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 018 - verify functionality of data type \'bit\', fetch as number', async function handler () {
const testdata2TsqlInsert = 1
const testParams = ParamsTester.getBitParams(
null,
testdata2TsqlInsert,
testdata2TsqlInsert)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 019 - verify functionality of data type \'float(53)\', fetch as number', async function handler () {
const testdata2Expected = '1.79E+308'
const testParams = ParamsTester.getFloatParams(
null,
testdata2Expected,
testdata2Expected, 53)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 020 - verify functionality of data type \'real\', fetch as number', async function handler () {
const testdata2Expected = '44.44000244140625'
const testParams = ParamsTester.getRealParams(
null,
testdata2Expected,
testdata2Expected)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 021 - verify functionality of data type \'binary(n)\', fetch as binary', async function handler () {
const testcolumnsize = 10
const testdata2TsqlInsert = 0x0123
const binaryBuffer = Buffer.from('00000000000000000123', 'hex')
const testParams = ParamsTester.getBinaryParams(
null,
binaryBuffer,
testdata2TsqlInsert, testcolumnsize
)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 022 - verify functionality of data type \'varbinary(n)\', fetch as binary', async function handler () {
const testcolumnsize = 10
const testdata2TsqlInsert = 0x0123
const binaryBuffer = Buffer.from('00000123', 'hex')
const testParams = ParamsTester.getVarBinaryParams(
null,
binaryBuffer,
testdata2TsqlInsert, testcolumnsize
)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 023 - verify functionality of data type \'varbinary(max)\', fetch as binary', async function handler () {
const testcolumnsize = 0
const testdata2TsqlInsert = 'CONVERT(varbinary(max), 0x0123456789AB)'
const binaryBuffer = Buffer.from('0123456789AB', 'hex')
const testParams = ParamsTester.getVarBinaryMaxParams(
null,
binaryBuffer,
testdata2TsqlInsert,
testcolumnsize
)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 023a - fetch large varbinary in chunks \'varbinary(max)\', fetch as binary', async function handler () {
const testcolumntype = ' varbinary(' + 'max' + ')'
const testcolumnname = 'col1'
const bufferSize = 0.5 * 1024 * 1024
const buffer = []
for (let i = 0; i < bufferSize; ++i) {
buffer[buffer.length] = i % 255
}
const binaryBuffer = Buffer.from(buffer)
await env.commonTestFnPromises.create(env.theConnection, tablename, testcolumnname, testcolumntype)
const promises = env.theConnection.promises
const insertSql = `insert into ${tablename} (${testcolumnname} ) values ( ? )`
await promises.query(insertSql, [binaryBuffer])
const selectSql = `select ${testcolumnname} from ${tablename}`
const r = await promises.query(selectSql, [binaryBuffer])
expect(r.first[0].col1).to.deep.equal(binaryBuffer)
})
it('test 024 - verify functionality of data type \'image\', fetch as binary', async function handler () {
const testcolumnsize = 2147483647
// var testdata2Expected = 0x0123
const testdata2TsqlInsert = 'CONVERT(varbinary(50), 0x0123456789AB)'
const binaryBuffer = Buffer.from('0123456789AB', 'hex')
const testParams = ParamsTester.getImageParams(
null,
binaryBuffer,
testdata2TsqlInsert,
testcolumnsize
)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 025 - verify functionality of data type \'xml\', fetch as text', async function handler () {
const testdata2Expected = '<data>zzzzz</data>'
const testdata2TsqlInsert = `'${testdata2Expected}'`
const testParams = ParamsTester.getXmlParams(
null,
testdata2Expected,
testdata2TsqlInsert
)
if (env.commonTestFns.SKIP_FAILING_TEST_ISSUE_36 === true) return
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 026 - verify functionality of data type \'char\', fetch as text', async function handler () {
const testcolumnsize = 10
const testdata2Expected = 'char data '
const testdata2TsqlInsert = `'${testdata2Expected}'`
const testParams = ParamsTester.getCharParams(
null,
testdata2Expected,
testdata2TsqlInsert,
testcolumnsize
)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 027 - verify functionality of data type \'varchar(n)\', fetch as text', async function handler () {
const testcolumnsize = 20
const testdata2Expected = 'varchar data'
const testdata2TsqlInsert = `'${testdata2Expected}'`
const testParams = ParamsTester.getVarCharParams(
null,
testdata2Expected,
testdata2TsqlInsert,
testcolumnsize
)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 028 - verify functionality of data type \'varchar(max)\', fetch as text', async function handler () {
const testcolumnsize = 0
const testdata2Expected = 'varchar_max data'
const testdata2TsqlInsert = `'${testdata2Expected}'`
const testParams = ParamsTester.getVarCharMaxParams(
null,
testdata2Expected,
testdata2TsqlInsert,
testcolumnsize
)
await ParamsTester.runTestParams(testParams)
// end of it():
})
it('test 029 - verify functionality of data type \'text\', fetch as text', async function handler () {
const testcolumnsize = 2147483647
const testdata2Expected = 'text data'
const testdata2TsqlInsert = `'${testdata2Expected}'`
const testParams = ParamsTester.getVarCharMaxParams(
null,
testdata2Expected,