Le 11/04/2010 09:37, Guillaume Lelarge a écrit :
> Le 21/03/2010 18:53, Dickson S. Guedes a écrit :
>> 2010/3/20 Guillaume Lelarge <[email protected]>:
>>> Applies and compiles with no issue.
>>
>> Good!
>>
>>> Anyways there are a few things that I don't like.
>>
>> I'm already wainting for. :-)
>>
>>> When the combobox contains the maximum number of queries, it should
>>> delete the older one and record the new one whereas now it simply
>>> doesn't do anything.
>>
>> Yes, i was in doubt whether I delete the oldest query or not, but your
>> review answers my doubt.
>>
>>> What happens when pgAdmin loads a queries file with more than the
>>> maximum number of queries in it? AFAICT, it loads everything. I think it
>>> shouldn't. It should only load the X last one (X being the maximum
>>> number of queries).
>>
>> I agree.
>>
>>> I don't think the default maximum query size is sane. 100 characters are
>>> really not enough. At least 1024 (much like track_activity_query_size).
>>> By the way, I also don't think we should talk in bytes. It's a number of
>>> characters.
>>
>> Sounds better for me, too.
>>
>>> I think that's all for me. Can you send us an updated patch?
>>
>> Yes, I can.
>>
>
> Did you find some time to finish this patch?
>
You won't need to. I changed your patch to mke it commitable. Patch
attached.
Comments?
--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com
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 @@
<resource>
<object class="wxDialog" name="frmOptions">
<title>Options</title>
- <size>350,315d</size>
+ <size>350,335d</size>
<style>wxDEFAULT_DIALOG_STYLE|wxCAPTION|wxSYSTEM_MENU|wxRESIZE_BORDER|wxRESIZE_BOX|wxTHICK_FRAME</style>
<object class="wxFlexGridSizer">
<cols>1</cols>
@@ -10,7 +10,7 @@
<growablecols>0</growablecols>
<object class="sizeritem">
<object class="wxNotebook" name="nbOptions">
- <size>346,290d</size>
+ <size>346,330d</size>
<object class="notebookpage">
<label>General</label>
<selected>1</selected>
@@ -561,6 +561,34 @@
<flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
</object>
+ <object class="sizeritem">
+ <object class="wxStaticText" name="lblHistoryMaxQueries">
+ <label>Maximum queries to store in history</label>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxTextCtrl" name="txtHistoryMaxQueries">
+ <value>10</value>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxStaticText" name="lblHistoryMaxQuerySize">
+ <label>Maximum size of a stored query (in bytes)</label>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxTextCtrl" name="txtHistoryMaxQuerySize">
+ <value>100</value>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
</object>
</object>
</object>
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;
}
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers