Skip to content

Commit 9dee407

Browse files
author
Daniel Schmidt
committed
Added unit tests for new function on statements.
1 parent 98aff92 commit 9dee407

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/Statement_test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,29 @@ TEST(Statement, getName)
918918
#endif
919919
}
920920

921+
TEST(Statement, getDeclaredType)
922+
{
923+
// Create a new database
924+
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
925+
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT, value DOUBLE)"));
926+
927+
SQLite::Statement query(db, "SELECT * FROM test");
928+
929+
const std::string decltype0 = query.getDeclaredType(0);
930+
const std::string decltype1 = query.getDeclaredType(1);
931+
const std::string decltype2 = query.getDeclaredType(2);
932+
EXPECT_EQ("INTEGER", decltype0);
933+
EXPECT_EQ("TEXT", decltype1);
934+
EXPECT_EQ("DOUBLE", decltype2);
935+
936+
// Index out of bounds.
937+
EXPECT_THROW(query.getDeclaredType(3), SQLite::Exception);
938+
939+
// Not a SELECT statement.
940+
SQLite::Statement insert(db, "INSERT INTO test VALUES (1, 'Hello', 3.1415)");
941+
EXPECT_THROW(insert.getDeclaredType(0), SQLite::Exception);
942+
}
943+
921944
#if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900)
922945
TEST(Statement, getColumns)
923946
{

0 commit comments

Comments
 (0)