mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 19:11:39 -06:00
Only register error log callback once at start of application
Instead of registering the error log callback function every time a database file is opened, we now register it only once when the application is first started. This way we can avoid calling sqlite_shutdown which can have unintended side effects. See issue #1932.
This commit is contained in:
@@ -87,6 +87,19 @@ static void sqlite_make_single_value(sqlite3_context* ctx, int num_arguments, sq
|
||||
});
|
||||
}
|
||||
|
||||
DBBrowserDB::DBBrowserDB() :
|
||||
_db(nullptr),
|
||||
db_used(false),
|
||||
isEncrypted(false),
|
||||
isReadOnly(false),
|
||||
dontCheckForStructureUpdates(false)
|
||||
{
|
||||
// Register error log callback. This needs to be done before SQLite is first used
|
||||
Callback<void(void*, int, const char*)>::func = std::bind(&DBBrowserDB::errorLogCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
void (*log_callback)(void*, int, const char*) = static_cast<decltype(log_callback)>(Callback<void(void*, int, const char*)>::callback);
|
||||
sqlite3_config(SQLITE_CONFIG_LOG, log_callback, nullptr);
|
||||
}
|
||||
|
||||
void DBBrowserDB::collationNeeded(void* /*pData*/, sqlite3* /*db*/, int eTextRep, const char* sCollationName)
|
||||
{
|
||||
QString name(sCollationName);
|
||||
@@ -149,12 +162,6 @@ bool DBBrowserDB::open(const QString& db, bool readOnly)
|
||||
if(tryEncryptionSettings(db, &isEncrypted, cipherSettings) == false)
|
||||
return false;
|
||||
|
||||
// Register error log callback. We need to make sure SQLite is being shut down before calling sqlite3_config.
|
||||
sqlite3_shutdown();
|
||||
Callback<void(void*, int, const char*)>::func = std::bind(&DBBrowserDB::errorLogCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
void (*log_callback)(void*, int, const char*) = static_cast<decltype(log_callback)>(Callback<void(void*, int, const char*)>::callback);
|
||||
sqlite3_config(SQLITE_CONFIG_LOG, log_callback, nullptr);
|
||||
|
||||
// Open database file
|
||||
if(sqlite3_open_v2(db.toUtf8(), &_db, readOnly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE, nullptr) != SQLITE_OK)
|
||||
{
|
||||
|
||||
@@ -65,7 +65,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
explicit DBBrowserDB () : _db(nullptr), db_used(false), isEncrypted(false), isReadOnly(false), dontCheckForStructureUpdates(false) {}
|
||||
explicit DBBrowserDB();
|
||||
~DBBrowserDB () override {}
|
||||
|
||||
bool open(const QString& db, bool readOnly = false);
|
||||
|
||||
Reference in New Issue
Block a user