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 .junit .jupiter .api .Assertions .fail ;
9
+ import static org .tarantool .jdbc .SqlAssertions .assertSqlExceptionHasStatus ;
9
10
10
11
import org .tarantool .util .SQLStates ;
11
12
16
17
17
18
import java .sql .ResultSet ;
18
19
import java .sql .SQLException ;
20
+ import java .sql .SQLFeatureNotSupportedException ;
19
21
import java .sql .Statement ;
20
22
21
23
public class JdbcStatementIT extends AbstractJdbcIT {
@@ -49,7 +51,7 @@ public void testExecuteWrongQuery() throws SQLException {
49
51
String wrongResultQuery = "INSERT INTO test(id, val) VALUES (40, 'forty')" ;
50
52
51
53
SQLException exception = assertThrows (SQLException .class , () -> stmt .executeQuery (wrongResultQuery ));
52
- SqlAssertions . assertSqlExceptionHasStatus (exception , SQLStates .NO_DATA );
54
+ assertSqlExceptionHasStatus (exception , SQLStates .NO_DATA );
53
55
}
54
56
55
57
@ Test
@@ -64,7 +66,7 @@ public void testExecuteWrongUpdate() throws SQLException {
64
66
String wrongUpdateQuery = "SELECT val FROM test" ;
65
67
66
68
SQLException exception = assertThrows (SQLException .class , () -> stmt .executeUpdate (wrongUpdateQuery ));
67
- SqlAssertions . assertSqlExceptionHasStatus (exception , SQLStates .TOO_MANY_RESULTS );
69
+ assertSqlExceptionHasStatus (exception , SQLStates .TOO_MANY_RESULTS );
68
70
}
69
71
70
72
@ Test
@@ -348,4 +350,59 @@ void testCloseOnCompletionMixedQueries() throws SQLException {
348
350
assertTrue (stmt .isClosed ());
349
351
}
350
352
353
+ @ Test
354
+ public void testMoreResultsWithResultSet () throws SQLException {
355
+ stmt .execute ("SELECT val FROM test WHERE id = 1" );
356
+
357
+ ResultSet rs = stmt .getResultSet ();
358
+
359
+ assertFalse (rs .isClosed ());
360
+ assertFalse (stmt .getMoreResults ());
361
+ assertEquals (-1 , stmt .getUpdateCount ());
362
+ assertTrue (rs .isClosed ());
363
+ }
364
+
365
+ @ Test
366
+ public void testMoreResultsWithUpdateCount () throws SQLException {
367
+ stmt .execute ("INSERT INTO test(id, val) VALUES (9, 'nine')" );
368
+
369
+ assertEquals (1 , stmt .getUpdateCount ());
370
+ assertFalse (stmt .getMoreResults ());
371
+ assertEquals (-1 , stmt .getUpdateCount ());
372
+ }
373
+
374
+ @ Test
375
+ public void testMoreResultsButCloseCurrent () throws SQLException {
376
+ stmt .execute ("SELECT val FROM test WHERE id = 1" );
377
+
378
+ ResultSet resultSet = stmt .getResultSet ();
379
+
380
+ assertFalse (resultSet .isClosed ());
381
+ assertFalse (stmt .getMoreResults (Statement .CLOSE_CURRENT_RESULT ));
382
+ assertEquals (-1 , stmt .getUpdateCount ());
383
+ assertTrue (resultSet .isClosed ());
384
+ }
385
+
386
+ @ Test
387
+ public void testMoreResultsButCloseAll () throws SQLException {
388
+ stmt .execute ("SELECT val FROM test WHERE id = 3" );
389
+ assertThrows (SQLFeatureNotSupportedException .class , () -> stmt .getMoreResults (Statement .CLOSE_ALL_RESULTS ));
390
+
391
+ stmt .execute ("INSERT INTO test(id, val) VALUES (21, 'twenty one')" );
392
+ assertEquals (1 , stmt .getUpdateCount ());
393
+ assertFalse (stmt .getMoreResults (Statement .CLOSE_ALL_RESULTS ));
394
+ assertEquals (-1 , stmt .getUpdateCount ());
395
+ }
396
+
397
+ @ Test
398
+ public void testMoreResultsButKeepCurrent () throws SQLException {
399
+ stmt .execute ("SELECT val FROM test WHERE id = 2" );
400
+ assertThrows (SQLFeatureNotSupportedException .class , () -> stmt .getMoreResults (Statement .KEEP_CURRENT_RESULT ));
401
+
402
+ stmt .execute ("INSERT INTO test(id, val) VALUES (22, 'twenty two')" );
403
+ assertEquals (1 , stmt .getUpdateCount ());
404
+ assertFalse (stmt .getMoreResults (Statement .KEEP_CURRENT_RESULT ));
405
+ assertEquals (-1 , stmt .getUpdateCount ());
406
+ }
407
+
351
408
}
0 commit comments