Added unit tests for new function on statements.

This commit is contained in:
Daniel Schmidt 2020-03-25 16:20:10 +01:00
parent 98aff92081
commit 9dee407ff0

View File

@ -918,6 +918,29 @@ TEST(Statement, getName)
#endif
}
TEST(Statement, getDeclaredType)
{
// Create a new database
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT, value DOUBLE)"));
SQLite::Statement query(db, "SELECT * FROM test");
const std::string decltype0 = query.getDeclaredType(0);
const std::string decltype1 = query.getDeclaredType(1);
const std::string decltype2 = query.getDeclaredType(2);
EXPECT_EQ("INTEGER", decltype0);
EXPECT_EQ("TEXT", decltype1);
EXPECT_EQ("DOUBLE", decltype2);
// Index out of bounds.
EXPECT_THROW(query.getDeclaredType(3), SQLite::Exception);
// Not a SELECT statement.
SQLite::Statement insert(db, "INSERT INTO test VALUES (1, 'Hello', 3.1415)");
EXPECT_THROW(insert.getDeclaredType(0), SQLite::Exception);
}
#if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900)
TEST(Statement, getColumns)
{