Unit test for Database SQLite::Exception

This commit is contained in:
Sébastien Rombauts 2014-03-15 21:30:28 +01:00
parent f3e9a779a1
commit d69045f3fc

View File

@ -119,7 +119,6 @@ TEST(Database, exec) {
remove("test.db3");
}
TEST(Database, execAndGet) {
remove("test.db3");
{
@ -141,3 +140,29 @@ TEST(Database, execAndGet) {
} // Close DB test.db3
remove("test.db3");
}
TEST(Database, execException) {
remove("test.db3");
{
// Create a new database
SQLite::Database db("test.db3", SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE);
// exception with SQL error: "no such table"
EXPECT_THROW(db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)"), SQLite::Exception);
// Create a new table
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT, weight INTEGER)");
// exception with SQL error: "table test has 3 columns but 2 values were supplied"
EXPECT_THROW(db.exec("INSERT INTO test VALUES (NULL, 3)"), SQLite::Exception);
// exception with SQL error: "No row to get a column from"
EXPECT_THROW(db.execAndGet("SELECT weight FROM test WHERE value=\"first\""), SQLite::Exception);
EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 3)"));
// exception with SQL error: "No row to get a column from"
EXPECT_THROW(db.execAndGet("SELECT weight FROM test WHERE value=\"second\""), SQLite::Exception);
} // Close DB test.db3
remove("test.db3");
}