#include #include #include #include #include #include #include #include #include namespace { using namespace testing; using namespace Sqlite3; struct InsertId { static std::string_view text() noexcept { return "INSERT INTO test (id) VALUES (42)"; } static void bind(sqlite3&, sqlite3_stmt&) {} }; struct GetIds { static std::string_view text() noexcept { return "SELECT id FROM test"; } static void bind(sqlite3&, sqlite3_stmt&) {} }; struct Sqlite3TransactionTest : Test { const Db mDb = makeDb(":memory:", "CREATE TABLE test ( id INTEGER )"); void insertId() const { Statement insertId(*mDb, InsertId{}); EXPECT_EQ(execute(*mDb, insertId), 1); } std::vector> getIds() const { Statement getIds(*mDb, GetIds{}); std::vector> result; request(*mDb, getIds, std::back_inserter(result), std::numeric_limits::max()); return result; } }; TEST_F(Sqlite3TransactionTest, shouldRollbackOnDestruction) { { const Transaction transaction(*mDb); insertId(); } EXPECT_THAT(getIds(), IsEmpty()); } TEST_F(Sqlite3TransactionTest, commitShouldCommitTransaction) { { Transaction transaction(*mDb); insertId(); transaction.commit(); } EXPECT_THAT(getIds(), ElementsAre(std::tuple(42))); } }