mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-04 00:44:19 +01:00
Merge 'Add multi select test in JDBC4StatementTest' from Kim Seon Woo
In reponse to [discord discussion](https://discord.com/channels/12586588 26257961020/1385754749634084885/1390535068401012858), I thought it would be better to add a test to show how JDBC4Statement can be used. Closes #1962
This commit is contained in:
@@ -2,6 +2,7 @@ package tech.turso.jdbc4;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -55,6 +56,30 @@ class JDBC4StatementTest {
|
||||
assertTrue(stmt.execute("SELECT * FROM users;"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void execute_select() throws Exception {
|
||||
stmt.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, username TEXT);");
|
||||
stmt.execute("INSERT INTO users VALUES (1, 'turso 1')");
|
||||
stmt.execute("INSERT INTO users VALUES (2, 'turso 2')");
|
||||
stmt.execute("INSERT INTO users VALUES (3, 'turso 3')");
|
||||
|
||||
ResultSet rs = stmt.executeQuery("SELECT * FROM users;");
|
||||
rs.next();
|
||||
int rowCount = 0;
|
||||
|
||||
do {
|
||||
rowCount++;
|
||||
int id = rs.getInt(1);
|
||||
String username = rs.getString(2);
|
||||
|
||||
assertEquals(id, rowCount);
|
||||
assertEquals(username, "turso " + rowCount);
|
||||
} while (rs.next());
|
||||
|
||||
assertEquals(rowCount, 3);
|
||||
assertFalse(rs.next());
|
||||
}
|
||||
|
||||
@Test
|
||||
void close_statement_test() throws Exception {
|
||||
stmt.close();
|
||||
|
||||
Reference in New Issue
Block a user