Skip to content

Commit

Permalink
move testResultSetForEach to DdbcTestFixture
Browse files Browse the repository at this point in the history
  • Loading branch information
SingingBush committed Nov 2, 2024
1 parent 095ea6d commit 84de0c2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
27 changes: 26 additions & 1 deletion test/ddbctest/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module ddbc.test.common;
import std.stdio : stdout, writeln;

import dunit;
import ddbc.core : Connection, Statement;
import ddbc.core : Connection, PreparedStatement, Statement;
import ddbc.common : createConnection;

class DdbcTestFixture {
Expand Down Expand Up @@ -67,4 +67,29 @@ class DdbcTestFixture {
//debug writeln("@AfterEach : closing db connection");
conn.close();
}

/*
* Ensure all supported databases can foreach a resultset
*/
@Test
public void testResultSetForEach() {
Statement stmt = conn.createStatement();
scope(exit) stmt.close();

stmt.executeUpdate(`INSERT INTO my_first_test (name) VALUES ('Goober')`);
stmt.executeUpdate(`INSERT INTO my_first_test (name) VALUES ('Goober')`);

PreparedStatement ps = conn.prepareStatement(`SELECT * FROM my_first_test WHERE name = ?`);
scope(exit) ps.close();

ps.setString(1, "Goober");

ddbc.core.ResultSet resultSet = ps.executeQuery();

int count = 0;
foreach (result; resultSet) {
count++;
}
assert(count == 2);
}
}
22 changes: 0 additions & 22 deletions test/ddbctest/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,6 @@ class SQLiteTest : DdbcTestFixture {
// assertEquals("long", to!string(id.type));
// assertEquals(2L, id.get!(long));
}

@Test
public void testResultSetForEach() {
Statement stmt = conn.createStatement();
scope(exit) stmt.close();

stmt.executeUpdate(`INSERT INTO my_first_test (name) VALUES ('Goober')`);
stmt.executeUpdate(`INSERT INTO my_first_test (name) VALUES ('Goober')`);

PreparedStatement ps = conn.prepareStatement(`SELECT * FROM my_first_test WHERE name = ?`);
scope(exit) ps.close();

ps.setString(1, "Goober");

ddbc.core.ResultSet resultSet = ps.executeQuery();

int count = 0;
foreach (result; resultSet) {
count++;
}
assert(count == 2);
}
}


Expand Down

0 comments on commit 84de0c2

Please sign in to comment.