@@ -219,6 +219,98 @@ void preparedStatementExecuteAfterCloseThrows() throws SQLException {
219219 assertThat (connection .executeCalls ).isZero ();
220220 }
221221
222+ @ Test
223+ void addBatchAfterCloseThrows () throws SQLException {
224+ RecordingConnection connection = new RecordingConnection (ROWS );
225+ Statement statement = connection .createStatement ();
226+ statement .close ();
227+
228+ assertThatThrownBy (() -> statement .addBatch ("insert into t(value) values (1)" ))
229+ .isInstanceOf (SQLException .class )
230+ .hasMessage ("Statement is closed" );
231+ assertThat (connection .executeCalls ).isZero ();
232+ }
233+
234+ @ Test
235+ void preparedAddBatchAfterCloseThrows () throws SQLException {
236+ RecordingConnection connection = new RecordingConnection (ROWS );
237+ LibsqlPreparedStatement statement =
238+ new LibsqlPreparedStatement (connection , "insert into t(value) values (?)" );
239+ statement .setLong (1 , 1L );
240+ statement .close ();
241+
242+ assertThatThrownBy (statement ::addBatch )
243+ .isInstanceOf (SQLException .class )
244+ .hasMessage ("Statement is closed" );
245+ assertThat (connection .executeCalls ).isZero ();
246+ }
247+
248+ @ Test
249+ void getGeneratedKeysAfterCloseThrows () throws SQLException {
250+ RecordingConnection connection = new RecordingConnection (ROWS );
251+ Statement statement = connection .createStatement ();
252+ statement .execute ("insert into t(value) values (1)" );
253+ statement .close ();
254+
255+ assertThatThrownBy (statement ::getGeneratedKeys )
256+ .isInstanceOf (SQLException .class )
257+ .hasMessage ("Statement is closed" );
258+ }
259+
260+ @ Test
261+ void preparedGetGeneratedKeysAfterCloseThrows () throws SQLException {
262+ RecordingConnection connection = new RecordingConnection (ROWS );
263+ LibsqlPreparedStatement statement =
264+ new LibsqlPreparedStatement (connection , "insert into t(value) values (1)" );
265+ statement .execute ();
266+ statement .close ();
267+
268+ assertThatThrownBy (statement ::getGeneratedKeys )
269+ .isInstanceOf (SQLException .class )
270+ .hasMessage ("Statement is closed" );
271+ }
272+
273+ @ Test
274+ void getResultSetAfterCloseThrows () throws SQLException {
275+ RecordingConnection connection = new RecordingConnection (ROWS );
276+ Statement statement = connection .createStatement ();
277+ statement .execute ("select value from t" );
278+ statement .close ();
279+
280+ assertThatThrownBy (statement ::getResultSet )
281+ .isInstanceOf (SQLException .class )
282+ .hasMessage ("Statement is closed" );
283+ }
284+
285+ @ Test
286+ void getResultSetAfterPostCloseExecuteThrows () throws SQLException {
287+ RecordingConnection connection = new RecordingConnection (ROWS );
288+ Statement statement = connection .createStatement ();
289+ statement .close ();
290+
291+ assertThat (statement .execute ("select value from t" )).isTrue ();
292+ assertThat (connection .executeCalls ).isEqualTo (1 );
293+ assertThatThrownBy (statement ::getResultSet )
294+ .isInstanceOf (SQLException .class )
295+ .hasMessage ("Statement is closed" );
296+ }
297+
298+ @ Test
299+ void preparedGetResultSetAfterPostCloseExecuteAttemptThrows () throws SQLException {
300+ RecordingConnection connection = new RecordingConnection (ROWS );
301+ LibsqlPreparedStatement statement =
302+ new LibsqlPreparedStatement (connection , "select value from t" );
303+ statement .close ();
304+
305+ assertThatThrownBy (statement ::execute )
306+ .isInstanceOf (SQLException .class )
307+ .hasMessage ("Statement is closed" );
308+ assertThatThrownBy (statement ::getResultSet )
309+ .isInstanceOf (SQLException .class )
310+ .hasMessage ("Statement is closed" );
311+ assertThat (connection .executeCalls ).isZero ();
312+ }
313+
222314 private static final class RecordingConnection extends LibsqlConnection {
223315 private final StmtResult result ;
224316 private int executeCalls ;
0 commit comments