mirror of
https://github.com/cuberite/SQLiteCpp.git
synced 2025-08-07 03:06:05 -04:00
Fix Savepoint_test comments and file formatting
This commit is contained in:
parent
7b61ad1095
commit
81a28af858
@ -18,19 +18,17 @@
|
|||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
TEST(Savepoint, commitRollback) {
|
TEST(Savepoint, commitRollback)
|
||||||
|
{
|
||||||
// Create a new database
|
// Create a new database
|
||||||
SQLite::Database db(":memory:",
|
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
|
||||||
SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
|
|
||||||
EXPECT_EQ(SQLite::OK, db.getErrorCode());
|
EXPECT_EQ(SQLite::OK, db.getErrorCode());
|
||||||
|
|
||||||
{
|
{
|
||||||
// Begin savepoint
|
// Begin savepoint
|
||||||
SQLite::Savepoint savepoint(db, "sp1");
|
SQLite::Savepoint savepoint(db, "sp1");
|
||||||
|
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
|
||||||
0,
|
|
||||||
db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)"));
|
|
||||||
EXPECT_EQ(SQLite::OK, db.getErrorCode());
|
EXPECT_EQ(SQLite::OK, db.getErrorCode());
|
||||||
|
|
||||||
// Insert a first value
|
// Insert a first value
|
||||||
@ -58,7 +56,8 @@ TEST(Savepoint, commitRollback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Auto rollback of a transaction on error / exception
|
// Auto rollback of a transaction on error / exception
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
// Begin savepoint
|
// Begin savepoint
|
||||||
SQLite::Savepoint savepoint(db, "sp3");
|
SQLite::Savepoint savepoint(db, "sp3");
|
||||||
|
|
||||||
@ -67,13 +66,13 @@ TEST(Savepoint, commitRollback) {
|
|||||||
EXPECT_EQ(2, db.getLastInsertRowid());
|
EXPECT_EQ(2, db.getLastInsertRowid());
|
||||||
|
|
||||||
// Execute with an error => exception with auto-rollback
|
// Execute with an error => exception with auto-rollback
|
||||||
db.exec(
|
db.exec("DesiredSyntaxError to raise an exception to rollback the transaction");
|
||||||
"DesiredSyntaxError to raise an exception to rollback the "
|
|
||||||
"transaction");
|
|
||||||
|
|
||||||
GTEST_FATAL_FAILURE_("we should never get there");
|
GTEST_FATAL_FAILURE_("we should never get there");
|
||||||
savepoint.release(); // We should never get there
|
savepoint.release(); // We should never get there
|
||||||
} catch (std::exception& e) {
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
std::cout << "SQLite exception: " << e.what() << std::endl;
|
std::cout << "SQLite exception: " << e.what() << std::endl;
|
||||||
// expected error, see above
|
// expected error, see above
|
||||||
}
|
}
|
||||||
@ -87,19 +86,18 @@ TEST(Savepoint, commitRollback) {
|
|||||||
EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'third')"));
|
EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, 'third')"));
|
||||||
EXPECT_EQ(2, db.getLastInsertRowid());
|
EXPECT_EQ(2, db.getLastInsertRowid());
|
||||||
|
|
||||||
// Execute a manual rollback (no real use case I can think of, so no
|
// Execute a manual rollback
|
||||||
// rollback() method)
|
savepoint.rollback();
|
||||||
db.exec("ROLLBACK");
|
|
||||||
|
|
||||||
// end of scope: the automatic rollback should not raise an error
|
// end of scope: the automatic rollback should not raise an error because it is harmless
|
||||||
// because it is harmless
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the results (expect only one row of result, as all other one have
|
// Check the results (expect only one row of result, as all other one have
|
||||||
// been rollbacked)
|
// been rollbacked)
|
||||||
SQLite::Statement query(db, "SELECT * FROM test");
|
SQLite::Statement query(db, "SELECT * FROM test");
|
||||||
int nbRows = 0;
|
int nbRows = 0;
|
||||||
while (query.executeStep()) {
|
while (query.executeStep())
|
||||||
|
{
|
||||||
nbRows++;
|
nbRows++;
|
||||||
EXPECT_EQ(1, query.getColumn(0).getInt());
|
EXPECT_EQ(1, query.getColumn(0).getInt());
|
||||||
EXPECT_STREQ("first", query.getColumn(1).getText());
|
EXPECT_STREQ("first", query.getColumn(1).getText());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user