6
6
import static org .junit .jupiter .api .Assertions .assertThrows ;
7
7
import static org .junit .jupiter .api .Assertions .assertTrue ;
8
8
import static org .tarantool .TestAssumptions .assumeMinimalServerVersion ;
9
+ import static org .tarantool .jdbc .SqlAssertions .assertSqlExceptionHasStatus ;
9
10
10
11
import org .tarantool .ServerVersion ;
11
12
import org .tarantool .TarantoolTestHelper ;
22
23
import java .sql .DriverManager ;
23
24
import java .sql .ResultSet ;
24
25
import java .sql .SQLException ;
26
+ import java .sql .SQLFeatureNotSupportedException ;
25
27
import java .sql .Statement ;
26
28
import java .util .Collections ;
27
29
import java .util .List ;
@@ -93,7 +95,7 @@ public void testExecuteWrongQuery() throws SQLException {
93
95
String wrongResultQuery = "INSERT INTO test(id, val) VALUES (40, 'forty')" ;
94
96
95
97
SQLException exception = assertThrows (SQLException .class , () -> stmt .executeQuery (wrongResultQuery ));
96
- SqlAssertions . assertSqlExceptionHasStatus (exception , SQLStates .NO_DATA );
98
+ assertSqlExceptionHasStatus (exception , SQLStates .NO_DATA );
97
99
}
98
100
99
101
@ Test
@@ -108,7 +110,7 @@ public void testExecuteWrongUpdate() throws SQLException {
108
110
String wrongUpdateQuery = "SELECT val FROM test" ;
109
111
110
112
SQLException exception = assertThrows (SQLException .class , () -> stmt .executeUpdate (wrongUpdateQuery ));
111
- SqlAssertions . assertSqlExceptionHasStatus (exception , SQLStates .TOO_MANY_RESULTS );
113
+ assertSqlExceptionHasStatus (exception , SQLStates .TOO_MANY_RESULTS );
112
114
}
113
115
114
116
@ Test
@@ -364,6 +366,61 @@ void testCloseOnCompletionMixedQueries() throws SQLException {
364
366
assertTrue (stmt .isClosed ());
365
367
}
366
368
369
+ @ Test
370
+ public void testMoreResultsWithResultSet () throws SQLException {
371
+ stmt .execute ("SELECT val FROM test WHERE id = 1" );
372
+
373
+ ResultSet rs = stmt .getResultSet ();
374
+
375
+ assertFalse (rs .isClosed ());
376
+ assertFalse (stmt .getMoreResults ());
377
+ assertEquals (-1 , stmt .getUpdateCount ());
378
+ assertTrue (rs .isClosed ());
379
+ }
380
+
381
+ @ Test
382
+ public void testMoreResultsWithUpdateCount () throws SQLException {
383
+ stmt .execute ("INSERT INTO test(id, val) VALUES (9, 'nine')" );
384
+
385
+ assertEquals (1 , stmt .getUpdateCount ());
386
+ assertFalse (stmt .getMoreResults ());
387
+ assertEquals (-1 , stmt .getUpdateCount ());
388
+ }
389
+
390
+ @ Test
391
+ public void testMoreResultsButCloseCurrent () throws SQLException {
392
+ stmt .execute ("SELECT val FROM test WHERE id = 1" );
393
+
394
+ ResultSet resultSet = stmt .getResultSet ();
395
+
396
+ assertFalse (resultSet .isClosed ());
397
+ assertFalse (stmt .getMoreResults (Statement .CLOSE_CURRENT_RESULT ));
398
+ assertEquals (-1 , stmt .getUpdateCount ());
399
+ assertTrue (resultSet .isClosed ());
400
+ }
401
+
402
+ @ Test
403
+ public void testMoreResultsButCloseAll () throws SQLException {
404
+ stmt .execute ("SELECT val FROM test WHERE id = 3" );
405
+ assertThrows (SQLFeatureNotSupportedException .class , () -> stmt .getMoreResults (Statement .CLOSE_ALL_RESULTS ));
406
+
407
+ stmt .execute ("INSERT INTO test(id, val) VALUES (21, 'twenty one')" );
408
+ assertEquals (1 , stmt .getUpdateCount ());
409
+ assertFalse (stmt .getMoreResults (Statement .CLOSE_ALL_RESULTS ));
410
+ assertEquals (-1 , stmt .getUpdateCount ());
411
+ }
412
+
413
+ @ Test
414
+ public void testMoreResultsButKeepCurrent () throws SQLException {
415
+ stmt .execute ("SELECT val FROM test WHERE id = 2" );
416
+ assertThrows (SQLFeatureNotSupportedException .class , () -> stmt .getMoreResults (Statement .KEEP_CURRENT_RESULT ));
417
+
418
+ stmt .execute ("INSERT INTO test(id, val) VALUES (22, 'twenty two')" );
419
+ assertEquals (1 , stmt .getUpdateCount ());
420
+ assertFalse (stmt .getMoreResults (Statement .KEEP_CURRENT_RESULT ));
421
+ assertEquals (-1 , stmt .getUpdateCount ());
422
+ }
423
+
367
424
private List <?> consoleSelect (Object key ) {
368
425
List <?> list = testHelper .evaluate (TestUtils .toLuaSelect ("TEST" , key ));
369
426
return list == null ? Collections .emptyList () : (List <?>) list .get (0 );
0 commit comments