22
22
import java .util .TimeZone ;
23
23
import java .util .UUID ;
24
24
25
+ import org .junit .Assert ;
25
26
import org .junit .jupiter .api .AfterAll ;
26
27
import org .junit .jupiter .api .BeforeAll ;
27
28
import org .junit .jupiter .api .Tag ;
@@ -57,6 +58,8 @@ public class CallableStatementTest extends AbstractTest {
57
58
.escapeIdentifier (RandomUtil .getIdentifier ("CallableStatementTest_inputParams_SP" ));
58
59
private static String conditionalSproc = AbstractSQLGenerator
59
60
.escapeIdentifier (RandomUtil .getIdentifier ("CallableStatementTest_conditionalSproc" ));
61
+ private static String simpleRetValSproc = AbstractSQLGenerator
62
+ .escapeIdentifier (RandomUtil .getIdentifier ("CallableStatementTest_simpleSproc" ));
60
63
private static String getObjectLocalDateTimeProcedureName = AbstractSQLGenerator
61
64
.escapeIdentifier (RandomUtil .getIdentifier ("CallableStatementTest_getObjectLocalDateTime_SP" ));
62
65
private static String getObjectOffsetDateTimeProcedureName = AbstractSQLGenerator
@@ -100,6 +103,7 @@ public static void setupTest() throws Exception {
100
103
TestUtils .dropProcedureIfExists (outOfOrderSproc , stmt );
101
104
TestUtils .dropProcedureIfExists (byParamNameSproc , stmt );
102
105
TestUtils .dropProcedureIfExists (conditionalSproc , stmt );
106
+ TestUtils .dropProcedureIfExists (simpleRetValSproc , stmt );
103
107
TestUtils .dropFunctionIfExists (userDefinedFunction , stmt );
104
108
TestUtils .dropUserDefinedTypeIfExists (manyParamUserDefinedType , stmt );
105
109
TestUtils .dropProcedureIfExists (manyParamProc , stmt );
@@ -119,6 +123,7 @@ public static void setupTest() throws Exception {
119
123
createOutOfOrderSproc ();
120
124
createByParamNameSproc ();
121
125
createConditionalProcedure ();
126
+ createSimpleRetValSproc ();
122
127
createUserDefinedFunction ();
123
128
}
124
129
}
@@ -1197,6 +1202,21 @@ public void testCallableStatementDefaultValues() throws SQLException {
1197
1202
}
1198
1203
}
1199
1204
1205
+ @ Test
1206
+ public void testCallableStatementSetByAnnotatedArgs () throws SQLException {
1207
+ String call = "{? = call " + simpleRetValSproc + " (@Arg1 = ?)}" ;
1208
+ int expectedValue = 1 ; // The sproc should return this value
1209
+
1210
+ try (CallableStatement cstmt = connection .prepareCall (call )) {
1211
+ cstmt .registerOutParameter (1 , Types .INTEGER );
1212
+ cstmt .setInt (1 , 2 );
1213
+ cstmt .setString (2 , "foo" );
1214
+ cstmt .execute ();
1215
+
1216
+ Assert .assertEquals (expectedValue , cstmt .getInt (1 ));
1217
+ }
1218
+ }
1219
+
1200
1220
@ Test
1201
1221
@ Tag (Constants .reqExternalSetup )
1202
1222
@ Tag (Constants .xAzureSQLDB )
@@ -1305,6 +1325,7 @@ public static void cleanup() throws SQLException {
1305
1325
TestUtils .dropProcedureIfExists (byParamNameSproc , stmt );
1306
1326
TestUtils .dropProcedureIfExists (currentTimeProc , stmt );
1307
1327
TestUtils .dropProcedureIfExists (conditionalSproc , stmt );
1328
+ TestUtils .dropProcedureIfExists (simpleRetValSproc , stmt );
1308
1329
TestUtils .dropFunctionIfExists (userDefinedFunction , stmt );
1309
1330
}
1310
1331
}
@@ -1373,6 +1394,13 @@ private static void createConditionalProcedure() throws SQLException {
1373
1394
}
1374
1395
}
1375
1396
1397
+ private static void createSimpleRetValSproc () throws SQLException {
1398
+ String sql = "CREATE PROCEDURE " + simpleRetValSproc + " (@Arg1 VARCHAR(128)) AS DECLARE @ReturnCode INT RETURN 1" ;
1399
+ try (Statement stmt = connection .createStatement ()) {
1400
+ stmt .execute (sql );
1401
+ }
1402
+ }
1403
+
1376
1404
private static void createTableManyParams () throws SQLException {
1377
1405
String type = manyParamUserDefinedType ;
1378
1406
String sql = "CREATE TABLE" + manyParamsTable + " (c1 " + type + " null, " + "c2 " + type + " null, " + "c3 "
0 commit comments