@@ -605,3 +605,256 @@ describe('Test Bind Varible', function () {
605
605
) ;
606
606
} ) ;
607
607
} ) ;
608
+
609
+ describe ( 'Verify stage binding and array binding' , ( ) => {
610
+
611
+ function generateDate ( year , month , day , hour , minute , second , millis ) {
612
+ const date = new Date ( ) ;
613
+ date . setFullYear ( year , month - 1 , day ) ;
614
+ date . setHours ( hour ) ;
615
+ date . setMinutes ( minute ) ;
616
+ date . setSeconds ( second ) ;
617
+ date . setMilliseconds ( millis ) ;
618
+
619
+ return date ;
620
+ }
621
+
622
+ function validateTimeValues ( actual , expected ) {
623
+ assert . strictEqual ( actual . length , expected . length ) ;
624
+
625
+ for ( let i = 0 ; i < actual . length ; i ++ ) {
626
+ assert . strictEqual ( Object . keys ( actual [ i ] ) . length , Object . keys ( expected [ i ] ) . length ) ;
627
+ Object . keys ( actual [ i ] ) . forEach ( ( key ) => key === 'C1' ? assert . strictEqual ( actual [ i ] [ key ] , expected [ i ] [ key ] ) : assert . strictEqual ( actual [ i ] [ key ] . toJSON ( ) , expected [ i ] [ key ] ) ) ;
628
+ }
629
+ }
630
+
631
+ let connection ;
632
+ const currentTimeZone = process . env . TZ ;
633
+ process . env . TZ = 'UTC' ;
634
+ const columns = '(c1 int, c2 timestamp_ntz , c3 timestamp_ltz, c4 timestamp_tz, c5 date);' ;
635
+ const arrayBindingTable = 'arrBinding' ;
636
+ const stageBindingTable = 'stageBinding' ;
637
+ const alterTimeZoneQuery = ( timeZone ) => `alter session set TIMEZONE = '${ timeZone } '` ;
638
+ const getCreateTableQuery = ( tableName ) => `Create or Replace table ${ tableName } ${ columns } ` ;
639
+ const getInsertQuery = ( tableName ) => `insert into ${ tableName } values (?, ?, ?, ?, ?)` ;
640
+ const selectQuery = ( tableName ) => `SELECT * FROM ${ tableName } order by c1` ;
641
+
642
+ const timeTestingValues = [
643
+ generateDate ( 1 , 1 , 1 , 23 , 24 , 25 , 987 ) ,
644
+ generateDate ( 9999 , 12 , 30 , 23 , 24 , 25 , 987 ) ,
645
+ generateDate ( 2025 , 2 , 18 , 11 , 37 , 25 , 326 ) ,
646
+ //SummerTime
647
+ generateDate ( 2024 , 6 , 22 , 23 , 37 , 25 , 520 ) ,
648
+ new Date ( 2000 , 0 , 1 )
649
+ ] ;
650
+
651
+ const binding = [ ] ;
652
+ timeTestingValues . forEach ( ( value , i ) => binding . push ( [ i , value , value , value , value ] ) ) ;
653
+
654
+ const testCases = [
655
+ {
656
+ timeZone : 'UTC' ,
657
+ expected :
658
+ [
659
+ {
660
+ C1 : 0 ,
661
+ C2 : '0001-01-01 23:24:25.987' ,
662
+ //Javascript Timezone limitation
663
+ C3 : '0001-01-01 23:24:25.987 +0000' ,
664
+ C4 : '0001-01-01 23:24:25.987 +0000' ,
665
+ C5 : '0001-01-01'
666
+ } ,
667
+ {
668
+ C1 : 1 ,
669
+ C2 : '9999-12-30 23:24:25.987' ,
670
+ C3 : '9999-12-30 23:24:25.987 +0000' ,
671
+ C4 : '9999-12-30 23:24:25.987 +0000' ,
672
+ C5 : '9999-12-30'
673
+
674
+ } ,
675
+ {
676
+ C1 : 2 ,
677
+ C2 : '2025-02-18 11:37:25.326' ,
678
+ C3 : '2025-02-18 11:37:25.326 +0000' ,
679
+ C4 : '2025-02-18 11:37:25.326 +0000' ,
680
+ C5 : '2025-02-18' ,
681
+ } ,
682
+ {
683
+ C1 : 3 ,
684
+ C2 : '2024-06-22 23:37:25.520' ,
685
+ C3 : '2024-06-22 23:37:25.520 +0000' ,
686
+ C4 : '2024-06-22 23:37:25.520 +0000' ,
687
+ C5 : '2024-06-22' ,
688
+ } ,
689
+ {
690
+ C1 : 4 ,
691
+ C2 : '2000-01-01 00:00:00.000' ,
692
+ C3 : '2000-01-01 00:00:00.000 +0000' ,
693
+ C4 : '2000-01-01 00:00:00.000 +0000' ,
694
+ C5 : '2000-01-01' ,
695
+ } ,
696
+ ] ,
697
+ } ,
698
+ {
699
+ timeZone : 'Europe/Warsaw' ,
700
+ expected :
701
+ [
702
+ {
703
+ C1 : 0 ,
704
+ C2 : '0001-01-01 23:24:25.987' ,
705
+ //Javascript Timezone limitation
706
+ C3 : '0001-01-02 00:48:25.987 +0124' ,
707
+ C4 : '0001-01-01 23:24:25.987 +0000' ,
708
+ C5 : '0001-01-01' ,
709
+ } ,
710
+ {
711
+ C1 : 1 ,
712
+ C2 : '9999-12-30 23:24:25.987' ,
713
+ C3 : '9999-12-31 00:24:25.987 +0100' ,
714
+ C4 : '9999-12-30 23:24:25.987 +0000' ,
715
+ C5 : '9999-12-30' ,
716
+ } ,
717
+ {
718
+ C1 : 2 ,
719
+ C2 : '2025-02-18 11:37:25.326' ,
720
+ C3 : '2025-02-18 12:37:25.326 +0100' ,
721
+ C4 : '2025-02-18 11:37:25.326 +0000' ,
722
+ C5 : '2025-02-18' ,
723
+ } ,
724
+ {
725
+ C1 : 3 ,
726
+ C2 : '2024-06-22 23:37:25.520' ,
727
+ C3 : '2024-06-23 01:37:25.520 +0200' ,
728
+ C4 : '2024-06-22 23:37:25.520 +0000' ,
729
+ C5 : '2024-06-22' ,
730
+ } ,
731
+ {
732
+ C1 : 4 ,
733
+ C2 : '2000-01-01 00:00:00.000' ,
734
+ C3 : '2000-01-01 01:00:00.000 +0100' ,
735
+ C4 : '2000-01-01 00:00:00.000 +0000' ,
736
+ C5 : '2000-01-01' ,
737
+ } ,
738
+ ] ,
739
+ } ,
740
+ {
741
+ timeZone : 'Asia/Tokyo' ,
742
+ expected :
743
+ [
744
+ {
745
+ C1 : 0 ,
746
+ C2 : '0001-01-01 23:24:25.987' ,
747
+ //Javascript Timezone limitation
748
+ C3 : '0001-01-02 08:43:24.987 +0918' ,
749
+ C4 : '0001-01-01 23:24:25.987 +0000' ,
750
+ C5 : '0001-01-01' ,
751
+ } ,
752
+ {
753
+ C1 : 1 ,
754
+ C2 : '9999-12-30 23:24:25.987' ,
755
+ C3 : '9999-12-31 08:24:25.987 +0900' ,
756
+ C4 : '9999-12-30 23:24:25.987 +0000' ,
757
+ C5 : '9999-12-30' ,
758
+ } ,
759
+ {
760
+ C1 : 2 ,
761
+ C2 : '2025-02-18 11:37:25.326' ,
762
+ C3 : '2025-02-18 20:37:25.326 +0900' ,
763
+ C4 : '2025-02-18 11:37:25.326 +0000' ,
764
+ C5 : '2025-02-18' ,
765
+ } ,
766
+ {
767
+ C1 : 3 ,
768
+ C2 : '2024-06-22 23:37:25.520' ,
769
+ //Tokyo does not have Summer time
770
+ C3 : '2024-06-23 08:37:25.520 +0900' ,
771
+ C4 : '2024-06-22 23:37:25.520 +0000' ,
772
+ C5 : '2024-06-22' ,
773
+ } ,
774
+ {
775
+ C1 : 4 ,
776
+ C2 : '2000-01-01 00:00:00.000' ,
777
+ C3 : '2000-01-01 09:00:00.000 +0900' ,
778
+ C4 : '2000-01-01 00:00:00.000 +0000' ,
779
+ C5 : '2000-01-01' ,
780
+ } ,
781
+ ]
782
+ } ,
783
+ {
784
+ timeZone : 'America/Los_Angeles' ,
785
+ expected :
786
+ [
787
+ {
788
+ C1 : 0 ,
789
+ C2 : '0001-01-01 23:24:25.987' ,
790
+ //Javascript Timezone limitation
791
+ C3 : '0001-01-01 15:31:27.987 -0752' ,
792
+ C4 : '0001-01-01 23:24:25.987 +0000' ,
793
+ C5 : '0001-01-01' ,
794
+ } ,
795
+ {
796
+ C1 : 1 ,
797
+ C2 : '9999-12-30 23:24:25.987' ,
798
+ C3 : '9999-12-30 15:24:25.987 -0800' ,
799
+ C4 : '9999-12-30 23:24:25.987 +0000' ,
800
+ C5 : '9999-12-30' ,
801
+ } ,
802
+ {
803
+ C1 : 2 ,
804
+ C2 : '2025-02-18 11:37:25.326' ,
805
+ //Summer Time
806
+ C3 : '2025-02-18 03:37:25.326 -0800' ,
807
+ C4 : '2025-02-18 11:37:25.326 +0000' ,
808
+ C5 : '2025-02-18' ,
809
+ } ,
810
+ {
811
+ C1 : 3 ,
812
+ C2 : '2024-06-22 23:37:25.520' ,
813
+ C3 : '2024-06-22 16:37:25.520 -0700' ,
814
+ C4 : '2024-06-22 23:37:25.520 +0000' ,
815
+ C5 : '2024-06-22' ,
816
+ } ,
817
+ {
818
+ C1 : 4 ,
819
+ C2 : '2000-01-01 00:00:00.000' ,
820
+ C3 : '1999-12-31 16:00:00.000 -0800' ,
821
+ C4 : '2000-01-01 00:00:00.000 +0000' ,
822
+ C5 : '2000-01-01' ,
823
+ } ,
824
+ ]
825
+ } ,
826
+ ] ;
827
+
828
+ beforeEach ( async ( ) => {
829
+ connection = testUtil . createConnection ( ) ;
830
+ await testUtil . connectAsync ( connection ) ;
831
+ await testUtil . executeCmdAsync ( connection , getCreateTableQuery ( arrayBindingTable ) ) ;
832
+ await testUtil . executeCmdAsync ( connection , getCreateTableQuery ( stageBindingTable ) ) ;
833
+ } ) ;
834
+
835
+ afterEach ( async ( ) => {
836
+ await testUtil . dropTablesIgnoringErrorsAsync ( connection , arrayBindingTable ) ;
837
+ await testUtil . dropTablesIgnoringErrorsAsync ( connection , stageBindingTable ) ;
838
+ await testUtil . destroyConnectionAsync ( connection ) ;
839
+ } ) ;
840
+
841
+ after ( ( ) => {
842
+ process . env . TZ = currentTimeZone ;
843
+ } ) ;
844
+
845
+ testCases . forEach ( ( { timeZone, expected } ) => {
846
+ it ( `test binding values with timezone ${ timeZone } ` , async ( ) => {
847
+ await testUtil . executeCmdAsync ( connection , alterTimeZoneQuery ( timeZone ) ) ;
848
+ await testUtil . executeCmdAsync ( connection , getInsertQuery ( arrayBindingTable ) , binding ) ;
849
+ await testUtil . destroyConnectionAsync ( connection , arrayBindingTable ) ;
850
+ connection = testUtil . createConnection ( { arrayBindingThreshold : 3 } ) ;
851
+ await testUtil . connectAsync ( connection ) ;
852
+ await testUtil . executeCmdAsync ( connection , alterTimeZoneQuery ( timeZone ) ) ;
853
+ await testUtil . executeCmdAsync ( connection , getInsertQuery ( stageBindingTable ) , binding ) ;
854
+ let rows = await testUtil . executeCmdAsync ( connection , selectQuery ( arrayBindingTable ) ) ;
855
+ validateTimeValues ( rows , expected ) ;
856
+ rows = await testUtil . executeCmdAsync ( connection , selectQuery ( stageBindingTable ) ) ;
857
+ validateTimeValues ( rows , expected ) ;
858
+ } ) ;
859
+ } ) ;
860
+ } ) ;
0 commit comments