mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Don't try to unlock the GncDbiSqlConnection when it was connected read-only.
If it's locked it's not *our* lock.
This commit is contained in:
@@ -89,9 +89,11 @@ GncDbiSqlConnection::GncDbiSqlConnection (DbType type, QofBackend* qbe,
|
||||
make_dbi_provider<DbType::DBI_MYSQL>() :
|
||||
make_dbi_provider<DbType::DBI_PGSQL>()},
|
||||
m_conn_ok{true}, m_last_error{ERR_BACKEND_NO_ERR}, m_error_repeat{0},
|
||||
m_retry{false}, m_sql_savepoint{0}
|
||||
m_retry{false}, m_sql_savepoint{0}, m_readonly{false}
|
||||
{
|
||||
if (mode != SESSION_READ_ONLY && !lock_database(mode == SESSION_BREAK_LOCK))
|
||||
if (mode == SESSION_READ_ONLY)
|
||||
m_readonly = true;
|
||||
else if (!lock_database(mode == SESSION_BREAK_LOCK))
|
||||
throw std::runtime_error("Failed to lock database!");
|
||||
if (!check_and_rollback_failed_save())
|
||||
{
|
||||
@@ -174,6 +176,7 @@ void
|
||||
GncDbiSqlConnection::unlock_database ()
|
||||
{
|
||||
if (m_conn == nullptr) return;
|
||||
if (m_readonly) return;
|
||||
g_return_if_fail (dbi_conn_error (m_conn, nullptr) == 0);
|
||||
|
||||
auto tables = m_provider->get_table_list (m_conn, lock_table);
|
||||
|
||||
@@ -108,6 +108,7 @@ private:
|
||||
*/
|
||||
bool m_retry;
|
||||
unsigned int m_sql_savepoint;
|
||||
bool m_readonly;
|
||||
bool lock_database(bool break_lock);
|
||||
void unlock_database();
|
||||
bool rename_table(const std::string& old_name, const std::string& new_name);
|
||||
|
||||
@@ -541,7 +541,7 @@ test_dbi_version_control (Fixture* fixture, gconstpointer pData)
|
||||
qof_session_end (sess);
|
||||
qof_session_destroy (sess);
|
||||
sess = qof_session_new (qof_book_new());
|
||||
qof_session_begin (sess, url, SESSION_NORMAL_OPEN);
|
||||
qof_session_begin (sess, url, SESSION_READ_ONLY);
|
||||
qof_session_load (sess, NULL);
|
||||
err = qof_session_pop_error (sess);
|
||||
g_assert_cmpint (err, == , ERR_SQL_DB_TOO_OLD);
|
||||
@@ -554,7 +554,7 @@ test_dbi_version_control (Fixture* fixture, gconstpointer pData)
|
||||
qof_session_end (sess);
|
||||
qof_session_destroy (sess);
|
||||
sess = qof_session_new (qof_book_new());
|
||||
qof_session_begin (sess, url, SESSION_NORMAL_OPEN);
|
||||
qof_session_begin (sess, url, SESSION_READ_ONLY);
|
||||
qof_session_load (sess, NULL);
|
||||
qof_session_ensure_all_data_loaded (sess);
|
||||
err = qof_session_pop_error (sess);
|
||||
|
||||
Reference in New Issue
Block a user