Skip to content

Commit f3e9a77

Browse files
committed
Added a test for Database::execAndGet()
1 parent f3023c0 commit f3e9a77

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

tests/Database_test.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ void assertion_failed(const char* apFile, const long apLine, const char* apFunc,
2828
#endif
2929

3030

31-
// Constructor
3231
TEST(Database, ctorExecCreateDropExist) {
3332
remove("test.db3");
3433
{
@@ -55,9 +54,7 @@ TEST(Database, ctorExecCreateDropExist) {
5554
remove("test.db3");
5655
}
5756

58-
59-
// Constructor
60-
TEST(Database, ctorExecAndGet) {
57+
TEST(Database, exec) {
6158
remove("test.db3");
6259
{
6360
// Create a new database
@@ -121,3 +118,26 @@ TEST(Database, ctorExecAndGet) {
121118
} // Close DB test.db3
122119
remove("test.db3");
123120
}
121+
122+
123+
TEST(Database, execAndGet) {
124+
remove("test.db3");
125+
{
126+
// Create a new database
127+
SQLite::Database db("test.db3", SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
128+
129+
// Create a new table with an explicit "id" column aliasing the underlying rowid
130+
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT, weight INTEGER)");
131+
132+
// insert a few rows
133+
EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)"));
134+
EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"second\", 5)"));
135+
EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"third\", 7)"));
136+
137+
// Get a single value result with an easy to use shortcut
138+
EXPECT_STREQ("second", db.execAndGet("SELECT value FROM test WHERE id=2"));
139+
EXPECT_STREQ("third", db.execAndGet("SELECT value FROM test WHERE weight=7"));
140+
EXPECT_EQ(3, (int)db.execAndGet("SELECT weight FROM test WHERE value=\"first\""));
141+
} // Close DB test.db3
142+
remove("test.db3");
143+
}

0 commit comments

Comments
 (0)