From 520a2a352b9d3bcff24e13458c9a51b04715d6cf Mon Sep 17 00:00:00 2001 From: mill-j Date: Sat, 24 Apr 2021 21:21:18 -0500 Subject: [PATCH 1/2] Fix Segfault And Remove Unneeded Mutex --- src/Database.cpp | 25 ++++++++----------------- src/Database.hpp | 3 --- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/Database.cpp b/src/Database.cpp index ade08a4..0df3632 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -36,7 +36,7 @@ void Database::CreateDatabase() try { - if (sqlite3_open("sample.hive", &m_Database) != SQLITE_OK && IsOK) + if (sqlite3_open("sample.hive", &m_Database) != SQLITE_OK) { wxLogDebug("Error opening DB"); throw sqlite3_errmsg(m_Database); @@ -81,13 +81,6 @@ void Database::InsertSample(int favorite, std::string filename, { try { - // while (!IsOK) - // { - // wxLogDebug("Waiting On Previous Transaction"); - // } - m.lock(); - - // rc = sqlite3_open("sample.hive", &m_Database); if (sqlite3_open("sample.hive", &m_Database) != SQLITE_OK) { wxLogDebug("Error opening DB"); @@ -118,10 +111,12 @@ void Database::InsertSample(int favorite, std::string filename, rc = sqlite3_bind_int(m_Stmt, 9, bitrate); rc = sqlite3_bind_text(m_Stmt, 10, path.c_str(), path.size(), SQLITE_STATIC); rc = sqlite3_bind_int(m_Stmt, 11, trashed); - - if (sqlite3_step(m_Stmt) != SQLITE_DONE) + + rc = sqlite3_step(m_Stmt); + + if (rc != SQLITE_DONE) { - wxLogDebug("No data inserted. Error code: %d", sqlite3_step(m_Stmt)); + wxLogDebug("No data inserted. Error code: %d", rc); } rc = sqlite3_finalize(m_Stmt); @@ -132,12 +127,11 @@ void Database::InsertSample(int favorite, std::string filename, // "Error! Cannot insert data into table.", // "Error", wxOK | wxICON_ERROR); // msgDialog.ShowModal(); - wxLogDebug("Error! Cannot insert data into table. Error code: %d, Error Message: %s", rc, m_ErrMsg); - sqlite3_free(m_ErrMsg); + wxLogDebug("Error! Cannot insert data into table. Error code: %d", rc); } else { - wxLogDebug("Data inserted successfully. %s", m_ErrMsg); + wxLogDebug("Data inserted successfully."); } if (rc == SQLITE_BUSY) @@ -162,13 +156,10 @@ void Database::InsertSample(int favorite, std::string filename, wxLogDebug("SQLITE_INTERNAL"); sqlite3_close(m_Database); - // IsOK = true; - m.unlock(); } catch (const std::exception &exception) { wxLogDebug(exception.what()); - m.unlock(); } } diff --git a/src/Database.hpp b/src/Database.hpp index 4c981dd..3482b58 100644 --- a/src/Database.hpp +++ b/src/Database.hpp @@ -21,9 +21,6 @@ class Database int rc; char* m_ErrMsg; sqlite3_stmt* m_Stmt; - - std::mutex m; - private: // ------------------------------------------------------------------- wxInfoBar& m_InfoBar; From a411e28c18f206d23c6a10582c17d31d453b2fa7 Mon Sep 17 00:00:00 2001 From: mill-j Date: Sun, 25 Apr 2021 12:41:22 -0500 Subject: [PATCH 2/2] Fixed SQLITE_BUSY Bug Database::HasSample failed to close database when sample found. --- src/Database.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Database.cpp b/src/Database.cpp index 0df3632..2e017fc 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -116,7 +116,7 @@ void Database::InsertSample(int favorite, std::string filename, if (rc != SQLITE_DONE) { - wxLogDebug("No data inserted. Error code: %d", rc); + wxLogDebug("No data inserted. Error code: %d: Msg: %s", rc , sqlite3_errmsg(m_Database)); } rc = sqlite3_finalize(m_Stmt); @@ -127,7 +127,7 @@ void Database::InsertSample(int favorite, std::string filename, // "Error! Cannot insert data into table.", // "Error", wxOK | wxICON_ERROR); // msgDialog.ShowModal(); - wxLogDebug("Error! Cannot insert data into table. Error code: %d", rc); + wxLogDebug("Error! Cannot insert data into table. Error code: %d: Msg: %s", rc , sqlite3_errmsg(m_Database)); } else { @@ -746,6 +746,7 @@ wxVector> Database::FilterDatabaseBySampleName(wxVector(sqlite3_column_text(m_Stmt, 0))); - return true; + haveSample = true; } rc = sqlite3_finalize(m_Stmt); @@ -778,6 +779,8 @@ bool Database::HasSample(std::string filename) } sqlite3_close(m_Database); + + return haveSample; } catch (const std::exception &exception) {