Add is_transaction_active() to all connectors (#550)

* Document the connector API method is_transaction_active()
* Move mysql::connection_base::is_transaction_active() to the other transaction-handling methods.
* Add more tests for mysql::connection::is_transaction_active()
* Add postgresql::connection_base::is_transaction_active()
* Add tests for postgresql::connection_base::is_transaction_active()
* Change the type of the SQLite3 transaction status from transaction_status_type to a boolean flag.
* Add sqlite3::connection_base::is_transaction_active()
* Add tests for sqlite3::connection_base::is_transaction_active()
* When closing a transaction do it in the following order: report (if any), execute SQL command, set transaction active flag to false.
This commit is contained in:
MeanSquaredError
2024-01-05 09:59:42 +02:00
committed by GitHub
parent 3474a4fa5d
commit 9b49afa306
7 changed files with 42 additions and 30 deletions

View File

@@ -53,6 +53,8 @@ int Transaction(int, char*[])
std::cerr << "--------------------------------------" << std::endl;
assert(db.is_transaction_active() == false);
auto current_level = db.get_default_isolation_level();
std::cout << "Expecting default isolation level = 1, is " << static_cast<int>(current_level) << std::endl;
assert(current_level == sqlpp::isolation_level::serializable);
@@ -66,6 +68,7 @@ int Transaction(int, char*[])
std::cerr << "Expecting read_uncommitted = 0, is: " << pragmaValue << std::endl;
db.set_default_isolation_level(sqlpp::isolation_level::read_uncommitted);
auto tx = start_transaction(db);
assert(db.is_transaction_active());
pragmaValue = db(custom_query(sqlpp::verbatim("PRAGMA read_uncommitted"))
.with_result_type_of(select(sqlpp::value(1).as(pragma))))
.front()
@@ -78,6 +81,7 @@ int Transaction(int, char*[])
assert(current_level == sqlpp::isolation_level::read_uncommitted);
tx.commit();
assert(db.is_transaction_active() == false);
std::cerr << "--------------------------------------" << std::endl;
return 0;