diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index b80b35d..6391fe3 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -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) {