mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Merge pull request #173 from volka/isolation_level
Implemented get/set_default_isolation_level() functions
This commit is contained in:
commit
a69230b930
@ -130,8 +130,19 @@ namespace sqlpp
|
||||
return t._prepare(*this);
|
||||
}
|
||||
|
||||
|
||||
//! set the transaction isolation level for the current connection
|
||||
/// time of effect is connector-specific, for most is will only affect new transactions
|
||||
void set_default_isolation_level(sqlpp::isolation_level);
|
||||
|
||||
//! read the default transaction isolation level for the current connection
|
||||
sqlpp::isolation_level get_default_isolation_level();
|
||||
|
||||
//! start transaction
|
||||
void start_transaction(isolation_level isolation = isolation_level::undefined);
|
||||
void start_transaction();
|
||||
|
||||
//! start transaction with defined isolation level (optional only for connectors that support it)
|
||||
void start_transaction(isolation_level isolation /* = isolation_level::undefined */);
|
||||
|
||||
//! commit transaction (or throw transaction if the transaction has been finished already)
|
||||
void commit_transaction();
|
||||
|
@ -38,6 +38,7 @@
|
||||
// an object to store internal Mock flags and values to validate in tests
|
||||
struct InternalMockData {
|
||||
sqlpp::isolation_level _last_isolation_level;
|
||||
sqlpp::isolation_level _default_isolation_level;
|
||||
};
|
||||
|
||||
template <bool enforceNullResultTreatment>
|
||||
@ -251,12 +252,26 @@ struct MockDbT : public sqlpp::connection
|
||||
return {name};
|
||||
}
|
||||
|
||||
void start_transaction()
|
||||
{
|
||||
_mock_data._last_isolation_level = _mock_data._default_isolation_level;
|
||||
}
|
||||
|
||||
void start_transaction(sqlpp::isolation_level level)
|
||||
{
|
||||
// store temporarily to verify the expected level was used in testcases
|
||||
_mock_data._last_isolation_level = level;
|
||||
}
|
||||
|
||||
void set_default_isolation_level(sqlpp::isolation_level level)
|
||||
{
|
||||
_mock_data._default_isolation_level = level;
|
||||
}
|
||||
|
||||
sqlpp::isolation_level get_default_isolation_level()
|
||||
{
|
||||
return _mock_data._default_isolation_level;
|
||||
}
|
||||
|
||||
void rollback_transaction(bool)
|
||||
{}
|
||||
|
||||
@ -266,6 +281,7 @@ struct MockDbT : public sqlpp::connection
|
||||
void report_rollback_failure(std::string)
|
||||
{}
|
||||
|
||||
// temporary data store to verify the expected results were produced
|
||||
InternalMockData _mock_data;
|
||||
};
|
||||
|
||||
|
@ -207,8 +207,22 @@ int Select(int, char* [])
|
||||
for_each_field(row, to_cerr{});
|
||||
}
|
||||
|
||||
auto transaction = start_transaction(db, sqlpp::isolation_level::read_committed);
|
||||
std::cout << (db._mock_data._last_isolation_level == sqlpp::isolation_level::read_committed) << std::endl;
|
||||
|
||||
{
|
||||
auto transaction = start_transaction(db, sqlpp::isolation_level::read_committed);
|
||||
if (db._mock_data._last_isolation_level != sqlpp::isolation_level::read_committed)
|
||||
{
|
||||
std::cout << "Error: transaction isolation level does not match expected level" << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
db.set_default_isolation_level(sqlpp::isolation_level::read_uncommitted);
|
||||
{
|
||||
auto transaction = start_transaction(db);
|
||||
if (db._mock_data._last_isolation_level != sqlpp::isolation_level::read_uncommitted)
|
||||
{
|
||||
std::cout << "Error: transaction isolation level does not match default level" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user