diff --git a/pgadmin/frm/frmOptions.cpp b/pgadmin/frm/frmOptions.cpp index 01872a6..a52dbb7 100644 --- a/pgadmin/frm/frmOptions.cpp +++ b/pgadmin/frm/frmOptions.cpp @@ -79,6 +79,8 @@ #define pickerFavouritesFile CTRL_FILEPICKER("pickerFavouritesFile") #define pickerMacrosFile CTRL_FILEPICKER("pickerMacrosFile") #define pickerHistoryFile CTRL_FILEPICKER("pickerHistoryFile") +#define txtHistoryMaxQueries CTRL_TEXT("txtHistoryMaxQueries") +#define txtHistoryMaxQuerySize CTRL_TEXT("txtHistoryMaxQuerySize") #define chkSQLUseSystemBackgroundColour CTRL_CHECKBOX("chkSQLUseSystemBackgroundColour") #define chkSQLUseSystemForegroundColour CTRL_CHECKBOX("chkSQLUseSystemForegroundColour") #define pickerSQLBackgroundColour CTRL_COLOURPICKER("pickerSQLBackgroundColour") @@ -200,6 +202,8 @@ frmOptions::frmOptions(frmMain *parent) txtMaxColSize->SetValidator(numval); txtAutoRowCount->SetValidator(numval); txtIndent->SetValidator(numval); + txtHistoryMaxQueries->SetValidator(numval); + txtHistoryMaxQuerySize->SetValidator(numval); pickerLogfile->SetPath(settings->GetLogFile()); radLoglevel->SetSelection(settings->GetLogLevel()); @@ -248,6 +252,9 @@ frmOptions::frmOptions(frmMain *parent) pickerMacrosFile->SetPath(settings->GetMacrosFile()); pickerHistoryFile->SetPath(settings->GetHistoryFile()); + txtHistoryMaxQueries->SetValue(NumToStr(settings->GetHistoryMaxQueries())); + txtHistoryMaxQuerySize->SetValue(NumToStr(settings->GetHistoryMaxQuerySize())); + chkSQLUseSystemBackgroundColour->SetValue(settings->GetSQLBoxUseSystemBackground()); chkSQLUseSystemForegroundColour->SetValue(settings->GetSQLBoxUseSystemForeground()); UpdateColourControls(); @@ -505,7 +512,9 @@ void frmOptions::OnOK(wxCommandEvent &ev) settings->SetSpacesForTabs(chkSpacesForTabs->GetValue()); settings->SetCopyQuoting(cbCopyQuote->GetCurrentSelection()); settings->SetCopyQuoteChar(cbCopyQuoteChar->GetValue()); - + settings->SetHistoryMaxQueries(StrToLong(txtHistoryMaxQueries->GetValue())); + settings->SetHistoryMaxQuerySize(StrToLong(txtHistoryMaxQuerySize->GetValue())); + wxString copySeparator = cbCopySeparator->GetValue(); if (copySeparator == _("Tab")) copySeparator = wxT("\t"); diff --git a/pgadmin/frm/frmQuery.cpp b/pgadmin/frm/frmQuery.cpp index b6a2364..5a628c6 100644 --- a/pgadmin/frm/frmQuery.cpp +++ b/pgadmin/frm/frmQuery.cpp @@ -2358,7 +2358,6 @@ void frmQuery::OnQueryComplete(wxCommandEvent &ev) sqlQueries->Delete(sqlQueries->GetCount()-1); btnDeleteCurrent->Enable(sqlQueries->GetValue().Length()>0); btnDeleteAll->Enable(sqlQueries->GetCount() > 0); - SaveQueries(); pgError err = sqlResult->GetResultError(); wxString errMsg = err.formatted_msg; @@ -2462,6 +2461,35 @@ void frmQuery::OnQueryComplete(wxCommandEvent &ev) } } + if (sqlResult->RunStatus() == PGRES_TUPLES_OK || sqlResult->RunStatus() == PGRES_COMMAND_OK) + { + // Delete the current query if its size is bigger than the max allowed + if (sqlQueries->GetString(sqlQueries->GetCount() - 1).Len() > settings->GetHistoryMaxQuerySize()) + { + histoQueries.RemoveAt(sqlQueries->GetCount() - 1); + sqlQueries->Delete(sqlQueries->GetCount() - 1); + } + else + { + // Delete an old query if it matches the current one + unsigned int index = histoQueries.Index(sqlQueries->GetString(sqlQueries->GetCount() - 1), false); + if (index != wxNOT_FOUND && index < sqlQueries->GetCount() - 1) + { + histoQueries.RemoveAt(index); + sqlQueries->Delete(index); + } + } + } + + // Make sure only the maximum query number is enforced + while (sqlQueries->GetCount() > settings->GetHistoryMaxQueries()) + { + histoQueries.RemoveAt(0); + sqlQueries->Delete(0); + } + + SaveQueries(); + completeQuery(done, qi->explain, qi->verbose); delete qi; } @@ -2778,6 +2806,17 @@ void frmQuery::LoadQueries() xmlFreeTextReader(reader); xmlCleanupParser(); + // Make sure only the maximum query number is enforced + if (sqlQueries->GetCount() > settings->GetHistoryMaxQueries()) + { + while (sqlQueries->GetCount() > settings->GetHistoryMaxQueries()) + { + histoQueries.RemoveAt(0); + sqlQueries->Delete(0); + } + SaveQueries(); + } + return; } @@ -2838,23 +2877,37 @@ void frmQuery::OnChangeQuery(wxCommandEvent &event) void frmQuery::OnDeleteCurrent(wxCommandEvent& event) { - histoQueries.RemoveAt(sqlQueries->GetSelection()); - sqlQueries->Delete(sqlQueries->GetSelection()); - sqlQueries->SetValue(wxT("")); - btnDeleteCurrent->Enable(false); - btnDeleteAll->Enable(sqlQueries->GetCount() > 0); - SaveQueries(); + + if ( wxMessageDialog(this, + _("Delete current query from history?"), + _("Confirm deletion"), + wxYES_NO | wxNO_DEFAULT | wxICON_EXCLAMATION).ShowModal() == wxID_YES ) + { + histoQueries.RemoveAt(sqlQueries->GetSelection()); + sqlQueries->Delete(sqlQueries->GetSelection()); + sqlQueries->SetValue(wxT("")); + btnDeleteCurrent->Enable(false); + btnDeleteAll->Enable(sqlQueries->GetCount() > 0); + SaveQueries(); + } } void frmQuery::OnDeleteAll(wxCommandEvent& event) { - histoQueries.Clear(); - sqlQueries->Clear(); - sqlQueries->SetValue(wxT("")); - btnDeleteCurrent->Enable(false); - btnDeleteAll->Enable(false); - SaveQueries(); + + if ( wxMessageDialog(this, + _("Delete all queries from history?"), + _("Confirm deletion"), + wxYES_NO | wxNO_DEFAULT |wxICON_EXCLAMATION).ShowModal() == wxID_YES ) + { + histoQueries.Clear(); + sqlQueries->Clear(); + sqlQueries->SetValue(wxT("")); + btnDeleteCurrent->Enable(false); + btnDeleteAll->Enable(false); + SaveQueries(); + } } diff --git a/pgadmin/include/utils/sysSettings.h b/pgadmin/include/utils/sysSettings.h index 4616d42..cbd4bd6 100644 --- a/pgadmin/include/utils/sysSettings.h +++ b/pgadmin/include/utils/sysSettings.h @@ -127,9 +127,13 @@ public: wxString GetFavouritesFile(); void SetFavouritesFile(const wxString &newval) { Write(wxT("FavouritesFile"), newval); } wxString GetMacrosFile(); - void SetMacrosFile(const wxString &newval) { Write(wxT("HistoryFile"), newval); } + void SetMacrosFile(const wxString &newval) { Write(wxT("MacrosFile"), newval); } wxString GetHistoryFile(); - void SetHistoryFile(const wxString &newval) { Write(wxT("HistoryFile"), newval); } + void SetHistoryFile(const wxString &newval) { Write(wxT("History/File"), newval); } + long GetHistoryMaxQueries() const { long l; Read(wxT("History/MaxQueries"), &l, 10L); return l; } + void SetHistoryMaxQueries(const long newval) { Write(wxT("History/MaxQueries"), newval); } + long GetHistoryMaxQuerySize() const { long l; Read(wxT("History/MaxQuerySize"), &l, 1024L); return l; } + void SetHistoryMaxQuerySize(const long newval) { Write(wxT("History/MaxQuerySize"), newval); } // Status Colours options wxString GetIdleProcessColour() const { wxString s; Read(wxT("IdleProcessColour"), &s, wxT("#5fa4d9")); return s; } diff --git a/pgadmin/ui/frmOptions.xrc b/pgadmin/ui/frmOptions.xrc index 1dc7c69..0799522 100644 --- a/pgadmin/ui/frmOptions.xrc +++ b/pgadmin/ui/frmOptions.xrc @@ -2,7 +2,7 @@ Options - 350,315d + 350,335d 1 @@ -10,7 +10,7 @@ 0 - 346,290d + 346,330d 1 @@ -561,6 +561,34 @@ wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT 4 + + + + + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + + + + 10 + + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + + + + + + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + + + + 100 + + wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT + 4 + diff --git a/pgadmin/utils/sysSettings.cpp b/pgadmin/utils/sysSettings.cpp index 7db580c..232d249 100644 --- a/pgadmin/utils/sysSettings.cpp +++ b/pgadmin/utils/sysSettings.cpp @@ -768,7 +768,7 @@ wxString sysSettings::GetHistoryFile() tmp += wxT("/.pgadmin_histoqueries"); #endif - Read(wxT("HistoryFile"), &s, tmp); + Read(wxT("History/File"), &s, tmp); return s; }