Fixed issue with samples not being deleted from database.

This commit is contained in:
apoorv569 2021-05-02 08:21:25 +05:30
parent 46c966bec2
commit 86e9c4a297
2 changed files with 29 additions and 15 deletions

View File

@ -466,6 +466,7 @@ void Browser::OnAutoImportDir()
wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_SMOOTH | wxPD_CAN_ABORT |
wxPD_AUTO_HIDE); wxPD_AUTO_HIDE);
progressDialog->CenterOnParent(wxBOTH); progressDialog->CenterOnParent(wxBOTH);
for ( size_t i = 0; i < number_of_files; i++) for ( size_t i = 0; i < number_of_files; i++)
{ {
name = files[i]; name = files[i];
@ -477,6 +478,7 @@ void Browser::OnAutoImportDir()
{ {
wxDir::GetAllFiles(name, &files); wxDir::GetAllFiles(name, &files);
} }
progressDialog->Pulse("Reading Samples",NULL); progressDialog->Pulse("Reading Samples",NULL);
} }
@ -485,11 +487,13 @@ void Browser::OnAutoImportDir()
for (size_t i = 0; i < files.size(); i++) for (size_t i = 0; i < files.size(); i++)
{ {
Browser::AddSamples(files[i]); Browser::AddSamples(files[i]);
progressDialog->Update(i, wxString::Format("Adding %s", files[i].AfterLast('/'))); progressDialog->Update(i, wxString::Format("Adding %s", files[i].AfterLast('/')));
if(progressDialog->WasCancelled()) if(progressDialog->WasCancelled())
break; break;
} }
progressDialog->Destroy(); progressDialog->Destroy();
} }
@ -794,7 +798,7 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
"%s from database? " "%s from database? "
"Warning this change is " "Warning this change is "
"permanent, and cannot be " "permanent, and cannot be "
"undone.", selection), "undone.", sample.AfterLast('/')),
wxMessageBoxCaptionStr, wxMessageBoxCaptionStr,
wxYES_NO | wxNO_DEFAULT | wxYES_NO | wxNO_DEFAULT |
wxICON_QUESTION | wxSTAY_ON_TOP | wxICON_QUESTION | wxSTAY_ON_TOP |
@ -817,8 +821,8 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
{ {
case wxID_YES: case wxID_YES:
{ {
msg = wxString::Format("Selected row: %d :: Sample: %s", selected_row, selection); msg = wxString::Format("Selected row: %d :: Sample: %s", selected_row, filename);
db.RemoveSampleFromDatabase(selection.ToStdString()); db.RemoveSampleFromDatabase(filename);
m_SampleListView->DeleteItem(selected_row); m_SampleListView->DeleteItem(selected_row);
} }
break; break;
@ -838,8 +842,12 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
for (int i = 0; i < rows; i++) for (int i = 0; i < rows; i++)
{ {
int row = m_SampleListView->ItemToRow(items[i]); int row = m_SampleListView->ItemToRow(items[i]);
wxString sel = m_SampleListView->GetTextValue(row, 1);
db.RemoveSampleFromDatabase(sel.ToStdString()); wxString text_value = m_SampleListView->GetTextValue(row, 1);
std::string multi_selection = text_value.Contains(wxString::Format(".%s", extension)) ?
text_value.BeforeLast('.').ToStdString() : text_value.ToStdString() ;
db.RemoveSampleFromDatabase(multi_selection);
m_SampleListView->DeleteItem(row); m_SampleListView->DeleteItem(row);
} }
} }
@ -865,9 +873,9 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
if (m_SampleListView->GetToggleValue(selected_row, 0)) if (m_SampleListView->GetToggleValue(selected_row, 0))
{ {
m_SampleListView->SetToggleValue(false, selected_row, 0); m_SampleListView->SetToggleValue(false, selected_row, 0);
db.UpdateFavoriteColumn(selection.BeforeLast('.').ToStdString(), 0); db.UpdateFavoriteColumn(filename, 0);
} }
db.UpdateTrashColumn(selection.BeforeLast('.').ToStdString(), 1); db.UpdateTrashColumn(filename, 1);
m_TrashedItems->AppendItem(trash_root_node, selection); m_TrashedItems->AppendItem(trash_root_node, selection);
m_SampleListView->DeleteItem(selected_row); m_SampleListView->DeleteItem(selected_row);
} }
@ -879,16 +887,16 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
for (int i = 0; i < rows; i++) for (int i = 0; i < rows; i++)
{ {
int row = m_SampleListView->ItemToRow(items[i]); int row = m_SampleListView->ItemToRow(items[i]);
wxString sel = m_SampleListView->GetTextValue(row, 1); wxString multi_selection = m_SampleListView->GetTextValue(row, 1);
if (m_SampleListView->GetToggleValue(row, 0)) if (m_SampleListView->GetToggleValue(row, 0))
{ {
m_SampleListView->SetToggleValue(false, row, 0); m_SampleListView->SetToggleValue(false, row, 0);
db.UpdateFavoriteColumn(sel.BeforeLast('.').ToStdString(), 0); db.UpdateFavoriteColumn(multi_selection.BeforeLast('.').ToStdString(), 0);
} }
db.UpdateTrashColumn(sel.BeforeLast('.').ToStdString(), 1); db.UpdateTrashColumn(multi_selection.BeforeLast('.').ToStdString(), 1);
m_TrashedItems->AppendItem(trash_root_node, sel); m_TrashedItems->AppendItem(trash_root_node, multi_selection);
m_SampleListView->DeleteItem(row); m_SampleListView->DeleteItem(row);
} }
} }
@ -926,7 +934,7 @@ void Browser::OnShowSampleListViewContextMenu(wxDataViewEvent& event)
void Browser::LoadDatabase() void Browser::LoadDatabase()
{ {
Settings settings(m_ConfigFilepath, m_DatabaseFilepath); Settings settings(this, m_ConfigFilepath, m_DatabaseFilepath);
Database db(*m_InfoBar); Database db(*m_InfoBar);
try try

View File

@ -113,7 +113,7 @@ void Database::InsertSample(int favorite, std::string filename,
rc = sqlite3_bind_int(m_Stmt, 11, trashed); rc = sqlite3_bind_int(m_Stmt, 11, trashed);
rc = sqlite3_step(m_Stmt); rc = sqlite3_step(m_Stmt);
if (rc != SQLITE_DONE) if (rc != SQLITE_DONE)
{ {
wxLogDebug("No data inserted. Error code: %d: Msg: %s", rc , sqlite3_errmsg(m_Database)); wxLogDebug("No data inserted. Error code: %d: Msg: %s", rc , sqlite3_errmsg(m_Database));
@ -155,7 +155,13 @@ void Database::InsertSample(int favorite, std::string filename,
if (rc == SQLITE_INTERNAL) if (rc == SQLITE_INTERNAL)
wxLogDebug("SQLITE_INTERNAL"); wxLogDebug("SQLITE_INTERNAL");
sqlite3_close(m_Database); rc = sqlite3_close(m_Database);
if (rc == SQLITE_OK)
wxLogDebug("DB Closed..");
else
wxLogDebug("Error! Cannot close DB, Error code: %d, Error message: %s", rc, m_ErrMsg);
} }
catch (const std::exception &exception) catch (const std::exception &exception)
{ {
@ -453,7 +459,7 @@ void Database::RemoveSampleFromDatabase(std::string filename)
{ {
rc = sqlite3_open("sample.hive", &m_Database); rc = sqlite3_open("sample.hive", &m_Database);
std::string remove = "DELETE * FROM SAMPLES WHERE FILENAME = ?;"; std::string remove = "DELETE FROM SAMPLES WHERE FILENAME = ?;";
rc = sqlite3_prepare_v2(m_Database, remove.c_str(), remove.size(), &m_Stmt, NULL); rc = sqlite3_prepare_v2(m_Database, remove.c_str(), remove.size(), &m_Stmt, NULL);