forked from microsoft/mssql-jdbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CallableStatementTest.java
2542 lines (2069 loc) · 134 KB
/
CallableStatementTest.java
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
/*
* Microsoft JDBC Driver for SQL Server Copyright(c) Microsoft Corporation All rights reserved. This program is made
* available under the terms of the MIT License. See the LICENSE file in the project root for more information.
*/
package com.microsoft.sqlserver.jdbc.AlwaysEncrypted;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.LinkedList;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import com.microsoft.sqlserver.jdbc.RandomData;
import com.microsoft.sqlserver.jdbc.RandomUtil;
import com.microsoft.sqlserver.jdbc.SQLServerCallableStatement;
import com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement;
import com.microsoft.sqlserver.jdbc.SQLServerResultSet;
import com.microsoft.sqlserver.jdbc.SQLServerStatement;
import com.microsoft.sqlserver.jdbc.TestResource;
import com.microsoft.sqlserver.jdbc.TestUtils;
import com.microsoft.sqlserver.testframework.AbstractSQLGenerator;
import com.microsoft.sqlserver.testframework.Constants;
import com.microsoft.sqlserver.testframework.PrepUtil;
import microsoft.sql.DateTimeOffset;
/**
* Test cases related to SQLServerCallableStatement.
*
*/
@RunWith(Parameterized.class)
@Tag(Constants.xSQLv12)
@Tag(Constants.xAzureSQLDW)
@Tag(Constants.xAzureSQLDB)
public class CallableStatementTest extends AESetup {
private static String multiStatementsProcedure = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("multiStatementsProcedure"));
private static String inputProcedure = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("inputProcedure"));
private static String inputProcedure2 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("inputProcedure2"));
private static String outputProcedure = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedure"));
private static String outputProcedure2 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedure2"));
private static String outputProcedure3 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedure3"));
private static String outputProcedure4 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedure4"));
private static String outputProcedureChar = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedureChar"));
private static String outputProcedureNumeric = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedureNumeric"));
private static String outputProcedureBinary = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedureBinary"));
private static String outputProcedureDate = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedureDate"));
private static String outputProcedureDateScale = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedureDateScale"));
private static String outputProcedureBatch = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("outputProcedureBatch"));
private static String inoutProcedure = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("inoutProcedure"));
private static String mixedProcedure = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("mixedProcedure"));
private static String mixedProcedure2 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("mixedProcedure2"));
private static String mixedProcedure3 = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("mixedProcedure3"));
private static String mixedProcedureNumericPrecisionScale = AbstractSQLGenerator
.escapeIdentifier(RandomUtil.getIdentifier("mixedProcedureNumericPrecisionScale"));
private static String table1 = TestUtils.escapeSingleQuotes(
AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table1")));
private static String table2 = TestUtils.escapeSingleQuotes(
AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table2")));
private static String table3 = TestUtils.escapeSingleQuotes(
AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table3")));
private static String table4 = TestUtils.escapeSingleQuotes(
AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table4")));
private static String table5 = TestUtils.escapeSingleQuotes(
AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table5")));
private static String table6 = TestUtils.escapeSingleQuotes(
AbstractSQLGenerator.escapeIdentifier(RandomUtil.getIdentifier("StoredProcedure_table6")));
private static String[] numericValues;
private static LinkedList<byte[]> byteValues;
private static String[] charValues;
private static LinkedList<Object> dateValues;
private static boolean nullable = false;
static String SP_table1[][] = {{"Char", "char(20) COLLATE Latin1_General_BIN2"},
{"Varchar", "varchar(50) COLLATE Latin1_General_BIN2"},};
static String SP_table2[][] = {{"Char", "char(20) COLLATE Latin1_General_BIN2"},
{"Varchar", "varchar(50) COLLATE Latin1_General_BIN2"},};
static String SP_table3[][] = {{"Bit", "bit"}, {"Tinyint", "tinyint"}, {"Smallint", "smallint"}, {"Int", "int"},
{"BigInt", "bigint"}, {"FloatDefault", "float"}, {"Float", "float(30)"}, {"Real", "real"},
{"DecimalDefault", "decimal(18,0)"}, {"Decimal", "decimal(10,5)"}, {"NumericDefault", "numeric(18,0)"},
{"Numeric", "numeric(8,2)"}, {"Int2", "int"}, {"SmallMoney", "smallmoney"}, {"Money", "money"},
{"Decimal2", "decimal(28,4)"}, {"Numeric2", "numeric(28,4)"},};
static String SP_table4[][] = {{"Int", "int"},};
/**
* Initialize the tables for this class. This method will execute AFTER the parent class (AESetup) finishes
* initializing.
*
* @throws SQLException
*/
@BeforeAll
public static void initValues() throws Exception {
numericValues = createNumericValues(nullable);
byteValues = createBinaryValues(nullable);
dateValues = createTemporalTypesCallableStatement(nullable);
charValues = createCharValues(nullable);
dropAll();
createSPTables(cekJks);
populateTable3();
populateTable4();
createTable(AETestConnectionString, CHAR_TABLE_AE, cekJks, charTable);
createTable(AETestConnectionString, NUMERIC_TABLE_AE, cekJks, numericTable);
createTable(AETestConnectionString, BINARY_TABLE_AE, cekJks, binaryTable);
createDateTableCallableStatement(cekJks);
populateCharNormalCase(AETestConnectionString, charValues);
populateNumericSetObject(AETestConnectionString, numericValues);
populateBinaryNormalCase(AETestConnectionString, byteValues);
populateDateNormalCase();
createTable(AETestConnectionString, SCALE_DATE_TABLE_AE, cekJks, dateScaleTable);
populateDateScaleNormalCase(AETestConnectionString, dateValues);
}
@AfterAll
public static void dropAll() throws Exception {
dropTables();
dropProcedures();
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testMultiInsertionSelection(String serverName, String url, String protocol) throws Exception {
createMultiInsertionSelection();
MultiInsertionSelection();
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testInputProcedureNumeric(String serverName, String url, String protocol) throws Exception {
createInputProcedure();
testInputProcedure("{call " + inputProcedure + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}", numericValues);
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testInputProcedureChar(String serverName, String url, String protocol) throws Exception {
createInputProcedure2();
testInputProcedure2("{call " + inputProcedure2 + "(?,?,?,?,?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testEncryptedOutputNumericParams(String serverName, String url, String protocol) throws Exception {
createOutputProcedure();
testOutputProcedureRandomOrder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues);
testOutputProcedureInorder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues);
testOutputProcedureReverseOrder("{call " + outputProcedure + "(?,?,?,?,?,?,?)}", numericValues);
testOutputProcedureRandomOrder("exec " + outputProcedure + " ?,?,?,?,?,?,?", numericValues);
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testUnencryptedAndEncryptedNumericOutputParams(String serverName, String url,
String protocol) throws Exception {
createOutputProcedure2();
testOutputProcedure2RandomOrder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues);
testOutputProcedure2Inorder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues);
testOutputProcedure2ReverseOrder("{call " + outputProcedure2 + "(?,?,?,?,?,?,?,?,?,?)}", numericValues);
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testEncryptedOutputParamsFromDifferentTables(String serverName, String url,
String protocol) throws Exception {
createOutputProcedure3();
testOutputProcedure3RandomOrder("{call " + outputProcedure3 + "(?,?)}");
testOutputProcedure3Inorder("{call " + outputProcedure3 + "(?,?)}");
testOutputProcedure3ReverseOrder("{call " + outputProcedure3 + "(?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testInOutProcedure(String serverName, String url, String protocol) throws Exception {
createInOutProcedure();
testInOutProcedure("{call " + inoutProcedure + "(?)}");
testInOutProcedure("exec " + inoutProcedure + " ?");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testMixedProcedure(String serverName, String url, String protocol) throws Exception {
createMixedProcedure();
testMixedProcedure("{ ? = call " + mixedProcedure + "(?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testUnencryptedAndEncryptedIOParams(String serverName, String url, String protocol) throws Exception {
// unencrypted input and output parameter
// encrypted input and output parameter
createMixedProcedure2();
testMixedProcedure2RandomOrder("{call " + mixedProcedure2 + "(?,?,?,?)}");
testMixedProcedure2Inorder("{call " + mixedProcedure2 + "(?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testUnencryptedIOParams(String serverName, String url, String protocol) throws Exception {
createMixedProcedure3();
testMixedProcedure3RandomOrder("{call " + mixedProcedure3 + "(?,?,?,?)}");
testMixedProcedure3Inorder("{call " + mixedProcedure3 + "(?,?,?,?)}");
testMixedProcedure3ReverseOrder("{call " + mixedProcedure3 + "(?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testVariousIOParams(String serverName, String url, String protocol) throws Exception {
createmixedProcedureNumericPrecisionScale();
testmixedProcedureNumericPrecisionScaleInorder("{call " + mixedProcedureNumericPrecisionScale + "(?,?,?,?)}");
testmixedProcedureNumericPrecisionScaleParameterName(
"{call " + mixedProcedureNumericPrecisionScale + "(?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testOutputProcedureChar(String serverName, String url, String protocol) throws Exception {
createOutputProcedureChar();
testOutputProcedureCharInorder("{call " + outputProcedureChar + "(?,?,?,?,?,?,?,?,?)}");
testOutputProcedureCharInorderObject("{call " + outputProcedureChar + "(?,?,?,?,?,?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testOutputProcedureNumeric(String serverName, String url, String protocol) throws Exception {
createOutputProcedureNumeric();
testOutputProcedureNumericInorder("{call " + outputProcedureNumeric + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
testcoerctionsOutputProcedureNumericInorder(
"{call " + outputProcedureNumeric + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testOutputProcedureBinary(String serverName, String url, String protocol) throws Exception {
createOutputProcedureBinary();
testOutputProcedureBinaryInorder("{call " + outputProcedureBinary + "(?,?,?,?,?)}");
testOutputProcedureBinaryInorderObject("{call " + outputProcedureBinary + "(?,?,?,?,?)}");
testOutputProcedureBinaryInorderString("{call " + outputProcedureBinary + "(?,?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testOutputProcedureDate(String serverName, String url, String protocol) throws Exception {
createOutputProcedureDate();
testOutputProcedureDateInorder("{call " + outputProcedureDate + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
testOutputProcedureDateInorderObject("{call " + outputProcedureDate + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testMixedProcedureDateScale(String serverName, String url, String protocol) throws Exception {
createMixedProcedureDateScale();
testMixedProcedureDateScaleInorder("{call " + outputProcedureDateScale + "(?,?,?,?,?,?)}");
testMixedProcedureDateScaleWithParameterName("{call " + outputProcedureDateScale + "(?,?,?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testOutputProcedureBatch(String serverName, String url, String protocol) throws Exception {
createOutputProcedureBatch();
testOutputProcedureBatchInorder("{call " + outputProcedureBatch + "(?,?,?,?)}");
}
@ParameterizedTest
@MethodSource("enclaveParams")
public void testOutputProcedure4(String serverName, String url, String protocol) throws Exception {
createOutputProcedure4();
}
private static void dropProcedures() throws SQLException {
try (Statement stmt = connection.createStatement()) {
TestUtils.dropProcedureIfExists(multiStatementsProcedure, stmt);
TestUtils.dropProcedureIfExists(inputProcedure, stmt);
TestUtils.dropProcedureIfExists(inputProcedure2, stmt);
TestUtils.dropProcedureIfExists(outputProcedure, stmt);
TestUtils.dropProcedureIfExists(outputProcedure2, stmt);
TestUtils.dropProcedureIfExists(outputProcedure3, stmt);
TestUtils.dropProcedureIfExists(outputProcedure4, stmt);
TestUtils.dropProcedureIfExists(outputProcedureChar, stmt);
TestUtils.dropProcedureIfExists(outputProcedureNumeric, stmt);
TestUtils.dropProcedureIfExists(outputProcedureBinary, stmt);
TestUtils.dropProcedureIfExists(outputProcedureDate, stmt);
TestUtils.dropProcedureIfExists(outputProcedureDateScale, stmt);
TestUtils.dropProcedureIfExists(outputProcedureBatch, stmt);
TestUtils.dropProcedureIfExists(inoutProcedure, stmt);
TestUtils.dropProcedureIfExists(mixedProcedure, stmt);
TestUtils.dropProcedureIfExists(mixedProcedure2, stmt);
TestUtils.dropProcedureIfExists(mixedProcedure3, stmt);
TestUtils.dropProcedureIfExists(mixedProcedureNumericPrecisionScale, stmt);
}
}
private static void dropTables() throws SQLException {
try (Statement stmt = connection.createStatement()) {
TestUtils.dropTableIfExists(table1, stmt);
TestUtils.dropTableIfExists(table2, stmt);
TestUtils.dropTableIfExists(table3, stmt);
TestUtils.dropTableIfExists(table4, stmt);
TestUtils.dropTableIfExists(CHAR_TABLE_AE, stmt);
TestUtils.dropTableIfExists(NUMERIC_TABLE_AE, stmt);
TestUtils.dropTableIfExists(BINARY_TABLE_AE, stmt);
TestUtils.dropTableIfExists(DATE_TABLE_AE, stmt);
TestUtils.dropTableIfExists(table5, stmt);
TestUtils.dropTableIfExists(table6, stmt);
TestUtils.dropTableIfExists(SCALE_DATE_TABLE_AE, stmt);
}
}
private static void createSPTables(String cekName) throws SQLException {
createTable(AETestConnectionString, table1, cekJks, SP_table1);
createTable(AETestConnectionString, table2, cekJks, SP_table2);
createTable(AETestConnectionString, table3, cekJks, SP_table3);
createTable(AETestConnectionString, table4, cekJks, SP_table4);
String sql = "create table " + table5 + " ("
+ "c1 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = "
+ cekJks + ") NULL,"
+ "c2 smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = "
+ cekJks + ") NULL,"
+ "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = "
+ cekJks + ") NULL," + ");";
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
Statement stmt = con.createStatement()) {
stmt.execute(sql);
} catch (SQLException e) {
fail(e.getMessage());
}
sql = "create table " + table6 + " ("
+ "c1 int ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = "
+ cekName + ") NULL,"
+ "c2 smallint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = "
+ cekName + ") NULL,"
+ "c3 bigint ENCRYPTED WITH (ENCRYPTION_TYPE = DETERMINISTIC, ALGORITHM = 'AEAD_AES_256_CBC_HMAC_SHA_256', COLUMN_ENCRYPTION_KEY = "
+ cekName + ") NULL," + ");";
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
Statement stmt = con.createStatement()) {
TestUtils.dropTableIfExists(table5, stmt);
TestUtils.dropTableIfExists(table6, stmt);
stmt.execute(sql);
} catch (SQLException e) {
fail(e.getMessage());
}
}
private static void populateTable4() throws SQLException {
String sql = "insert into " + table4 + " values( " + "?,?,?" + ")";
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
PreparedStatement pstmt = TestUtils.getPreparedStmt(con, sql, stmtColEncSetting)) {
// bit
for (int i = 1; i <= 3; i++) {
pstmt.setInt(i, Integer.parseInt(numericValues[3]));
}
pstmt.execute();
}
}
private static void populateTable3() throws SQLException {
String sql = "insert into " + table3 + " values( " + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?,"
+ "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?," + "?,?,?,"
+ "?,?,?," + "?,?,?," + "?,?,?" + ")";
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerPreparedStatement pstmt = (SQLServerPreparedStatement) TestUtils.getPreparedStmt(con, sql,
stmtColEncSetting)) {
// bit
for (int i = 1; i <= 3; i++) {
if (numericValues[0].equalsIgnoreCase(Boolean.TRUE.toString())) {
pstmt.setBoolean(i, true);
} else {
pstmt.setBoolean(i, false);
}
}
// tinyint
for (int i = 4; i <= 6; i++) {
pstmt.setShort(i, Short.valueOf(numericValues[1]));
}
// smallint
for (int i = 7; i <= 9; i++) {
pstmt.setShort(i, Short.parseShort(numericValues[2]));
}
// int
for (int i = 10; i <= 12; i++) {
pstmt.setInt(i, Integer.parseInt(numericValues[3]));
}
// bigint
for (int i = 13; i <= 15; i++) {
pstmt.setLong(i, Long.parseLong(numericValues[4]));
}
// float default
for (int i = 16; i <= 18; i++) {
pstmt.setDouble(i, Double.parseDouble(numericValues[5]));
}
// float(30)
for (int i = 19; i <= 21; i++) {
pstmt.setDouble(i, Double.parseDouble(numericValues[6]));
}
// real
for (int i = 22; i <= 24; i++) {
pstmt.setFloat(i, Float.parseFloat(numericValues[7]));
}
// decimal default
for (int i = 25; i <= 27; i++) {
if (numericValues[8].equalsIgnoreCase("0"))
pstmt.setBigDecimal(i, new BigDecimal(numericValues[8]), 18, 0);
else
pstmt.setBigDecimal(i, new BigDecimal(numericValues[8]));
}
// decimal(10,5)
for (int i = 28; i <= 30; i++) {
pstmt.setBigDecimal(i, new BigDecimal(numericValues[9]), 10, 5);
}
// numeric
for (int i = 31; i <= 33; i++) {
if (numericValues[10].equalsIgnoreCase("0"))
pstmt.setBigDecimal(i, new BigDecimal(numericValues[10]), 18, 0);
else
pstmt.setBigDecimal(i, new BigDecimal(numericValues[10]));
}
// numeric(8,2)
for (int i = 34; i <= 36; i++) {
pstmt.setBigDecimal(i, new BigDecimal(numericValues[11]), 8, 2);
}
// int2
for (int i = 37; i <= 39; i++) {
pstmt.setInt(i, Integer.parseInt(numericValues[3]));
}
// smallmoney
for (int i = 40; i <= 42; i++) {
pstmt.setSmallMoney(i, new BigDecimal(numericValues[12]));
}
// money
for (int i = 43; i <= 45; i++) {
pstmt.setMoney(i, new BigDecimal(numericValues[13]));
}
// decimal(28,4)
for (int i = 46; i <= 48; i++) {
pstmt.setBigDecimal(i, new BigDecimal(numericValues[14]), 28, 4);
}
// numeric(28,4)
for (int i = 49; i <= 51; i++) {
pstmt.setBigDecimal(i, new BigDecimal(numericValues[15]), 28, 4);
}
pstmt.execute();
}
}
private void createMultiInsertionSelection() throws SQLException {
String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'"
+ TestUtils.escapeSingleQuotes(multiStatementsProcedure)
+ "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)" + " DROP PROCEDURE " + multiStatementsProcedure;
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
stmt.execute(sql);
sql = "CREATE PROCEDURE " + multiStatementsProcedure
+ " (@p0 char(20) = null, @p1 char(20) = null, @p2 char(20) = null, "
+ "@p3 varchar(50) = null, @p4 varchar(50) = null, @p5 varchar(50) = null)" + " AS"
+ " INSERT INTO " + table1 + " values (@p0,@p1,@p2,@p3,@p4,@p5)" + " INSERT INTO " + table2
+ " values (@p0,@p1,@p2,@p3,@p4,@p5)" + " SELECT * FROM " + table1 + " SELECT * FROM " + table2;
stmt.execute(sql);
}
}
private void MultiInsertionSelection() throws SQLException {
String sql = "{call " + multiStatementsProcedure + " (?,?,?,?,?,?)}";
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
// char, varchar
for (int i = 1; i <= 3; i++) {
callableStatement.setString(i, charValues[0]);
}
for (int i = 4; i <= 6; i++) {
callableStatement.setString(i, charValues[1]);
}
boolean results = callableStatement.execute();
// skip update count which is given by insertion
while (false == results && (-1) != callableStatement.getUpdateCount()) {
results = callableStatement.getMoreResults();
}
while (results) {
try (ResultSet rs = callableStatement.getResultSet()) {
int numberOfColumns = rs.getMetaData().getColumnCount();
while (rs.next()) {
testGetString(rs, numberOfColumns);
}
}
results = callableStatement.getMoreResults();
}
} catch (SQLException e) {
fail(e.getMessage());
}
}
private void testGetString(ResultSet rs, int numberOfColumns) throws SQLException {
for (int i = 1; i <= numberOfColumns; i = i + 3) {
String stringValue1 = "" + rs.getString(i);
String stringValue2 = "" + rs.getString(i + 1);
String stringValue3 = "" + rs.getString(i + 2);
assertTrue(stringValue1.equalsIgnoreCase(stringValue2) && stringValue2.equalsIgnoreCase(stringValue3),
"Decryption failed with getString(): " + stringValue1 + ", " + stringValue2 + ", " + stringValue3
+ ".\n");
}
}
private void createInputProcedure() throws SQLException {
String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'"
+ TestUtils.escapeSingleQuotes(inputProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)"
+ " DROP PROCEDURE " + inputProcedure;
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
stmt.execute(sql);
sql = "CREATE PROCEDURE " + inputProcedure + " @p0 int, @p1 decimal(18, 0), "
+ "@p2 float, @p3 real, @p4 numeric(18, 0), @p5 smallmoney, @p6 money,"
+ "@p7 bit, @p8 smallint, @p9 bigint, @p10 float(30), @p11 decimal(10,5), @p12 numeric(8,2), "
+ "@p13 decimal(28,4), @p14 numeric(28,4) " + " AS" + " SELECT top 1 RandomizedInt FROM "
+ NUMERIC_TABLE_AE + " where DeterministicInt=@p0 and DeterministicDecimalDefault=@p1 and "
+ " DeterministicFloatDefault=@p2 and DeterministicReal=@p3 and DeterministicNumericDefault=@p4 and"
+ " DeterministicSmallMoney=@p5 and DeterministicMoney=@p6 and DeterministicBit=@p7 and"
+ " DeterministicSmallint=@p8 and DeterministicBigint=@p9 and DeterministicFloat=@p10 and"
+ " DeterministicDecimal=@p11 and DeterministicNumeric=@p12 and DeterministicDecimal2=@p13 and"
+ " DeterministicNumeric2=@p14 ";
stmt.execute(sql);
}
}
private void testInputProcedure(String sql, String[] values) throws SQLException {
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.setInt(1, Integer.parseInt(values[3]));
if (RandomData.returnZero)
callableStatement.setBigDecimal(2, new BigDecimal(values[8]), 18, 0);
else
callableStatement.setBigDecimal(2, new BigDecimal(values[8]));
callableStatement.setDouble(3, Double.parseDouble(values[5]));
callableStatement.setFloat(4, Float.parseFloat(values[7]));
if (RandomData.returnZero)
callableStatement.setBigDecimal(5, new BigDecimal(values[10]), 18, 0); // numeric(18,0)
else
callableStatement.setBigDecimal(5, new BigDecimal(values[10])); // numeric(18,0)
callableStatement.setSmallMoney(6, new BigDecimal(values[12]));
callableStatement.setMoney(7, new BigDecimal(values[13]));
if (values[0].equalsIgnoreCase(Boolean.TRUE.toString()))
callableStatement.setBoolean(8, true);
else
callableStatement.setBoolean(8, false);
callableStatement.setShort(9, Short.parseShort(values[2])); // smallint
callableStatement.setLong(10, Long.parseLong(values[4])); // bigint
callableStatement.setDouble(11, Double.parseDouble(values[6])); // float30
callableStatement.setBigDecimal(12, new BigDecimal(values[9]), 10, 5); // decimal(10,5)
callableStatement.setBigDecimal(13, new BigDecimal(values[11]), 8, 2); // numeric(8,2)
callableStatement.setBigDecimal(14, new BigDecimal(values[14]), 28, 4);
callableStatement.setBigDecimal(15, new BigDecimal(values[15]), 28, 4);
try (SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery()) {
rs.next();
assertEquals(rs.getString(1), values[3], "" + TestResource.getResource("R_inputParamFailed"));
}
} catch (Exception e) {
fail(e.getMessage());
}
}
private void createInputProcedure2() throws SQLException {
String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'"
+ TestUtils.escapeSingleQuotes(inputProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)"
+ " DROP PROCEDURE " + inputProcedure2;
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
stmt.execute(sql);
sql = "CREATE PROCEDURE " + inputProcedure2
+ " @p0 varchar(50), @p1 uniqueidentifier, @p2 varchar(max), @p3 nchar(30), @p4 nvarchar(60), @p5 nvarchar(max), "
+ " @p6 varchar(8000), @p7 nvarchar(4000)" + " AS"
+ " SELECT top 1 RandomizedVarchar, DeterministicUniqueidentifier, DeterministicVarcharMax, RandomizedNchar, "
+ " DeterministicNvarchar, DeterministicNvarcharMax, DeterministicVarchar8000, RandomizedNvarchar4000 FROM "
+ CHAR_TABLE_AE + " where DeterministicVarchar = @p0 and DeterministicUniqueidentifier =@p1";
stmt.execute(sql);
}
}
private void testInputProcedure2(String sql) throws SQLException {
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.setString(1, charValues[1]);
callableStatement.setUniqueIdentifier(2, charValues[6]);
callableStatement.setString(3, charValues[2]);
callableStatement.setNString(4, charValues[3]);
callableStatement.setNString(5, charValues[4]);
callableStatement.setNString(6, charValues[5]);
callableStatement.setString(7, charValues[7]);
callableStatement.setNString(8, charValues[8]);
try (SQLServerResultSet rs = (SQLServerResultSet) callableStatement.executeQuery()) {
rs.next();
assertEquals(rs.getString(1).trim(), charValues[1], TestResource.getResource("R_inputParamFailed"));
assertEquals(rs.getUniqueIdentifier(2), charValues[6].toUpperCase(),
TestResource.getResource("R_inputParamFailed"));
assertEquals(rs.getString(3).trim(), charValues[2], TestResource.getResource("R_inputParamFailed"));
assertEquals(rs.getString(4).trim(), charValues[3], TestResource.getResource("R_inputParamFailed"));
assertEquals(rs.getString(5).trim(), charValues[4], TestResource.getResource("R_inputParamFailed"));
assertEquals(rs.getString(6).trim(), charValues[5], TestResource.getResource("R_inputParamFailed"));
assertEquals(rs.getString(7).trim(), charValues[7], TestResource.getResource("R_inputParamFailed"));
assertEquals(rs.getString(8).trim(), charValues[8], TestResource.getResource("R_inputParamFailed"));
}
} catch (Exception e) {
fail(e.getMessage());
}
}
private void createOutputProcedure3() throws SQLException {
String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'"
+ TestUtils.escapeSingleQuotes(outputProcedure3) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)"
+ " DROP PROCEDURE " + outputProcedure3;
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
stmt.execute(sql);
sql = "CREATE PROCEDURE " + outputProcedure3 + " @p0 int OUTPUT, @p1 int OUTPUT " + " AS"
+ " SELECT top 1 @p0=DeterministicInt FROM " + table3 + " SELECT top 1 @p1=RandomizedInt FROM "
+ table4;
stmt.execute(sql);
}
}
private void testOutputProcedure3RandomOrder(String sql) throws SQLException {
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
callableStatement.execute();
int intValue2 = callableStatement.getInt(2);
assertEquals("" + intValue2, numericValues[3], TestResource.getResource("R_outputParamFailed"));
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed"));
int intValue3 = callableStatement.getInt(2);
assertEquals("" + intValue3, numericValues[3], TestResource.getResource("R_outputParamFailed"));
int intValue4 = callableStatement.getInt(2);
assertEquals("" + intValue4, numericValues[3], TestResource.getResource("R_outputParamFailed"));
int intValue5 = callableStatement.getInt(1);
assertEquals("" + intValue5, numericValues[3], TestResource.getResource("R_outputParamFailed"));
} catch (Exception e) {
fail(e.getMessage());
}
}
private void testOutputProcedure3Inorder(String sql) throws SQLException {
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
callableStatement.execute();
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed"));
int intValue2 = callableStatement.getInt(2);
assertEquals("" + intValue2, numericValues[3], TestResource.getResource("R_outputParamFailed"));
} catch (Exception e) {
fail(e.getMessage());
}
}
private void testOutputProcedure3ReverseOrder(String sql) throws SQLException {
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
callableStatement.execute();
int intValue2 = callableStatement.getInt(2);
assertEquals("" + intValue2, numericValues[3], TestResource.getResource("R_outputParamFailed"));
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, numericValues[3], TestResource.getResource("R_outputParamFailed"));
} catch (Exception e) {
fail(e.getMessage());
}
}
private void createOutputProcedure2() throws SQLException {
String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'"
+ TestUtils.escapeSingleQuotes(outputProcedure2) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)"
+ " DROP PROCEDURE " + outputProcedure2;
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
stmt.execute(sql);
sql = "CREATE PROCEDURE " + outputProcedure2
+ " @p0 int OUTPUT, @p1 int OUTPUT, @p2 smallint OUTPUT, @p3 smallint OUTPUT, @p4 tinyint OUTPUT, @p5 tinyint OUTPUT, @p6 smallmoney OUTPUT,"
+ " @p7 smallmoney OUTPUT, @p8 money OUTPUT, @p9 money OUTPUT " + " AS"
+ " SELECT top 1 @p0=PlainInt, @p1=DeterministicInt, @p2=PlainSmallint,"
+ " @p3=RandomizedSmallint, @p4=PlainTinyint, @p5=DeterministicTinyint, @p6=DeterministicSmallMoney, @p7=PlainSmallMoney,"
+ " @p8=PlainMoney, @p9=DeterministicMoney FROM " + table3;
stmt.execute(sql);
}
}
private void testOutputProcedure2RandomOrder(String sql, String[] values) throws SQLException {
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT);
callableStatement.registerOutParameter(4, java.sql.Types.SMALLINT);
callableStatement.registerOutParameter(5, java.sql.Types.TINYINT);
callableStatement.registerOutParameter(6, java.sql.Types.TINYINT);
callableStatement.registerOutParameter(7, microsoft.sql.Types.SMALLMONEY);
callableStatement.registerOutParameter(8, microsoft.sql.Types.SMALLMONEY);
callableStatement.registerOutParameter(9, microsoft.sql.Types.MONEY);
callableStatement.registerOutParameter(10, microsoft.sql.Types.MONEY);
callableStatement.execute();
BigDecimal ecnryptedSmallMoney = callableStatement.getSmallMoney(7);
assertEquals("" + ecnryptedSmallMoney, values[12], TestResource.getResource("R_outputParamFailed"));
short encryptedSmallint = callableStatement.getShort(4);
assertEquals("" + encryptedSmallint, values[2], TestResource.getResource("R_outputParamFailed"));
BigDecimal SmallMoneyValue = callableStatement.getSmallMoney(8);
assertEquals("" + SmallMoneyValue, values[12], TestResource.getResource("R_outputParamFailed"));
short encryptedTinyint = callableStatement.getShort(6);
assertEquals("" + encryptedTinyint, values[1], TestResource.getResource("R_outputParamFailed"));
short tinyintValue = callableStatement.getShort(5);
assertEquals("" + tinyintValue, values[1], TestResource.getResource("R_outputParamFailed"));
BigDecimal encryptedMoneyValue = callableStatement.getMoney(9);
assertEquals("" + encryptedMoneyValue, values[13], TestResource.getResource("R_outputParamFailed"));
short smallintValue = callableStatement.getShort(3);
assertEquals("" + smallintValue, values[2], TestResource.getResource("R_outputParamFailed"));
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, values[3], TestResource.getResource("R_outputParamFailed"));
BigDecimal encryptedSmallMoney = callableStatement.getMoney(10);
assertEquals("" + encryptedSmallMoney, values[13], TestResource.getResource("R_outputParamFailed"));
int encryptedInt = callableStatement.getInt(2);
assertEquals("" + encryptedInt, values[3], TestResource.getResource("R_outputParamFailed"));
} catch (Exception e) {
fail(e.getMessage());
}
}
private void testOutputProcedure2Inorder(String sql, String[] values) throws SQLException {
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT);
callableStatement.registerOutParameter(4, java.sql.Types.SMALLINT);
callableStatement.registerOutParameter(5, java.sql.Types.TINYINT);
callableStatement.registerOutParameter(6, java.sql.Types.TINYINT);
callableStatement.registerOutParameter(7, microsoft.sql.Types.SMALLMONEY);
callableStatement.registerOutParameter(8, microsoft.sql.Types.SMALLMONEY);
callableStatement.registerOutParameter(9, microsoft.sql.Types.MONEY);
callableStatement.registerOutParameter(10, microsoft.sql.Types.MONEY);
callableStatement.execute();
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, values[3], TestResource.getResource("R_outputParamFailed"));
int encryptedInt = callableStatement.getInt(2);
assertEquals("" + encryptedInt, values[3], TestResource.getResource("R_outputParamFailed"));
short smallintValue = callableStatement.getShort(3);
assertEquals("" + smallintValue, values[2], TestResource.getResource("R_outputParamFailed"));
short encryptedSmallint = callableStatement.getShort(4);
assertEquals("" + encryptedSmallint, values[2], TestResource.getResource("R_outputParamFailed"));
short tinyintValue = callableStatement.getShort(5);
assertEquals("" + tinyintValue, values[1], TestResource.getResource("R_outputParamFailed"));
short encryptedTinyint = callableStatement.getShort(6);
assertEquals("" + encryptedTinyint, values[1], TestResource.getResource("R_outputParamFailed"));
BigDecimal encryptedSmallMoney = callableStatement.getSmallMoney(7);
assertEquals("" + encryptedSmallMoney, values[12], TestResource.getResource("R_outputParamFailed"));
BigDecimal SmallMoneyValue = callableStatement.getSmallMoney(8);
assertEquals("" + SmallMoneyValue, values[12], TestResource.getResource("R_outputParamFailed"));
BigDecimal MoneyValue = callableStatement.getMoney(9);
assertEquals("" + MoneyValue, values[13], TestResource.getResource("R_outputParamFailed"));
BigDecimal encryptedMoney = callableStatement.getMoney(10);
assertEquals("" + encryptedMoney, values[13], TestResource.getResource("R_outputParamFailed"));
} catch (Exception e) {
fail(e.getMessage());
}
}
private void testOutputProcedure2ReverseOrder(String sql, String[] values) throws SQLException {
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(2, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT);
callableStatement.registerOutParameter(4, java.sql.Types.SMALLINT);
callableStatement.registerOutParameter(5, java.sql.Types.TINYINT);
callableStatement.registerOutParameter(6, java.sql.Types.TINYINT);
callableStatement.registerOutParameter(7, microsoft.sql.Types.SMALLMONEY);
callableStatement.registerOutParameter(8, microsoft.sql.Types.SMALLMONEY);
callableStatement.registerOutParameter(9, microsoft.sql.Types.MONEY);
callableStatement.registerOutParameter(10, microsoft.sql.Types.MONEY);
callableStatement.execute();
BigDecimal encryptedMoney = callableStatement.getMoney(10);
assertEquals("" + encryptedMoney, values[13], TestResource.getResource("R_outputParamFailed"));
BigDecimal MoneyValue = callableStatement.getMoney(9);
assertEquals("" + MoneyValue, values[13], TestResource.getResource("R_outputParamFailed"));
BigDecimal SmallMoneyValue = callableStatement.getSmallMoney(8);
assertEquals("" + SmallMoneyValue, values[12], TestResource.getResource("R_outputParamFailed"));
BigDecimal encryptedSmallMoney = callableStatement.getSmallMoney(7);
assertEquals("" + encryptedSmallMoney, values[12], TestResource.getResource("R_outputParamFailed"));
short encryptedTinyint = callableStatement.getShort(6);
assertEquals("" + encryptedTinyint, values[1], TestResource.getResource("R_outputParamFailed"));
short tinyintValue = callableStatement.getShort(5);
assertEquals("" + tinyintValue, values[1], TestResource.getResource("R_outputParamFailed"));
short encryptedSmallint = callableStatement.getShort(4);
assertEquals("" + encryptedSmallint, values[2], TestResource.getResource("R_outputParamFailed"));
short smallintValue = callableStatement.getShort(3);
assertEquals("" + smallintValue, values[2], TestResource.getResource("R_outputParamFailed"));
int encryptedInt = callableStatement.getInt(2);
assertEquals("" + encryptedInt, values[3], TestResource.getResource("R_outputParamFailed"));
int intValue = callableStatement.getInt(1);
assertEquals("" + intValue, values[3], TestResource.getResource("R_outputParamFailed"));
} catch (Exception e) {
fail(e.getMessage());
}
}
private void createOutputProcedure() throws SQLException {
String sql = " IF EXISTS (select * from sysobjects where id = object_id(N'"
+ TestUtils.escapeSingleQuotes(outputProcedure) + "') and OBJECTPROPERTY(id, N'IsProcedure') = 1)"
+ " DROP PROCEDURE " + outputProcedure;
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerStatement stmt = (SQLServerStatement) con.createStatement()) {
stmt.execute(sql);
sql = "CREATE PROCEDURE " + outputProcedure + " @p0 int OUTPUT, @p1 float OUTPUT, @p2 smallint OUTPUT, "
+ "@p3 bigint OUTPUT, @p4 tinyint OUTPUT, @p5 smallmoney OUTPUT, @p6 money OUTPUT " + " AS"
+ " SELECT top 1 @p0=RandomizedInt, @p1=DeterministicFloatDefault, @p2=RandomizedSmallint,"
+ " @p3=RandomizedBigint, @p4=DeterministicTinyint, @p5=DeterministicSmallMoney, @p6=DeterministicMoney FROM "
+ table3;
stmt.execute(sql);
}
}
private void testOutputProcedureRandomOrder(String sql, String[] values) throws SQLException {
try (Connection con = PrepUtil.getConnection(AETestConnectionString, AEInfo);
SQLServerCallableStatement callableStatement = (SQLServerCallableStatement) TestUtils
.getCallableStmt(con, sql, stmtColEncSetting)) {
callableStatement.registerOutParameter(1, java.sql.Types.INTEGER);
callableStatement.registerOutParameter(2, java.sql.Types.DOUBLE);
callableStatement.registerOutParameter(3, java.sql.Types.SMALLINT);
callableStatement.registerOutParameter(4, java.sql.Types.BIGINT);
callableStatement.registerOutParameter(5, java.sql.Types.TINYINT);
callableStatement.registerOutParameter(6, microsoft.sql.Types.SMALLMONEY);
callableStatement.registerOutParameter(7, microsoft.sql.Types.MONEY);
callableStatement.execute();
double floatValue0 = callableStatement.getDouble(2);