mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-04 09:46:02 -04:00
Unit test for Database SQLite::Exception
This commit is contained in:
parent
f3e9a779a1
commit
d69045f3fc
@ -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");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user