1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-11-16 14:25:19 -05:00

Fix sqlite3 map shutdown fails due to missing to finalize list statement

Add error output on fail to shutdown sqlite3 map db
Implement shutdown of sqlite3 rollback db
This commit is contained in:
sapier 2014-06-22 02:31:24 +02:00
parent d4245e6cac
commit 9056c163a7
2 changed files with 69 additions and 28 deletions

View File

@ -339,13 +339,28 @@ void Database_SQLite3::listAllLoadableBlocks(std::list<v3s16> &dst)
}
}
#define FINALIZE_STATEMENT(statement) \
if ( statement ) \
rc = sqlite3_finalize(statement); \
if ( rc != SQLITE_OK ) \
errorstream << "Database_SQLite3::~Database_SQLite3():" \
<< "Failed to finalize: " << #statement << ": rc=" << rc << std::endl;
Database_SQLite3::~Database_SQLite3()
{
if(m_database_read)
sqlite3_finalize(m_database_read);
if(m_database_write)
sqlite3_finalize(m_database_write);
int rc = SQLITE_OK;
FINALIZE_STATEMENT(m_database_read)
FINALIZE_STATEMENT(m_database_write)
FINALIZE_STATEMENT(m_database_list)
if(m_database)
sqlite3_close(m_database);
rc = sqlite3_close(m_database);
if (rc != SQLITE_OK) {
errorstream << "Database_SQLite3::~Database_SQLite3(): "
<< "Failed to close database: rc=" << rc << std::endl;
}
}

View File

@ -1091,10 +1091,36 @@ public:
SQL_databaseCheck();
}
#define FINALIZE_STATEMENT(statement) \
if ( statement ) \
rc = sqlite3_finalize(statement); \
if ( rc != SQLITE_OK ) \
errorstream << "RollbackManager::~RollbackManager():" \
<< "Failed to finalize: " << #statement << ": rc=" << rc << std::endl;
~RollbackManager() {
infostream << "RollbackManager::~RollbackManager()" << std::endl;
flush();
int rc = SQLITE_OK;
FINALIZE_STATEMENT(dbs_insert)
FINALIZE_STATEMENT(dbs_replace)
FINALIZE_STATEMENT(dbs_select)
FINALIZE_STATEMENT(dbs_select_range)
FINALIZE_STATEMENT(dbs_select_withActor)
FINALIZE_STATEMENT(dbs_knownActor_select)
FINALIZE_STATEMENT(dbs_knownActor_insert)
FINALIZE_STATEMENT(dbs_knownNode_select)
FINALIZE_STATEMENT(dbs_knownNode_insert)
if(dbh)
rc = sqlite3_close(dbh);
if (rc != SQLITE_OK) {
errorstream << "RollbackManager::~RollbackManager(): "
<< "Failed to close database: rc=" << rc << std::endl;
}
}
void addAction(const RollbackAction &action) {