Hi,

Now that I'm done translating the 9.0 PostgreSQL manual, I get back to
pgAdmin's coding. I know we didn't deliver yet 1.12, but I can start the
work on my git branches.

So, this patch adds a new contextual menu to individual table and
function. This menu allows one to reset this specific table (or
function) statistics.

Comments?

PS: of course, I won't commit until we branch out 1.12.


-- 
Guillaume
 http://www.postgresql.fr
 http://dalibo.com
diff --git a/pgadmin/frm/frmMain.cpp b/pgadmin/frm/frmMain.cpp
index 2e1d707..ae1a579 100644
--- a/pgadmin/frm/frmMain.cpp
+++ b/pgadmin/frm/frmMain.cpp
@@ -68,6 +68,7 @@
 #include "dlg/dlgServer.h"
 #include "dlg/dlgDatabase.h"
 #include "schema/pgTable.h"
+#include "schema/pgFunction.h"
 #include "schema/pgIndex.h"
 #include "schema/pgTrigger.h"
 #include "schema/pgRole.h"
@@ -341,6 +342,8 @@ void frmMain::CreateMenus()
     new dropCascadedFactory(menuFactories, editMenu, 0);
     new truncateFactory(menuFactories, editMenu, 0);
     new truncateCascadedFactory(menuFactories, editMenu, 0);
+    new resetTableStatsFactory(menuFactories, editMenu, 0);
+    new resetFunctionStatsFactory(menuFactories, editMenu, 0);
     new reassignDropOwnedFactory(menuFactories, editMenu, 0);
     editMenu->AppendSeparator();
 
diff --git a/pgadmin/include/schema/pgFunction.h b/pgadmin/include/schema/pgFunction.h
index 9940bec..749d752 100644
--- a/pgadmin/include/schema/pgFunction.h
+++ b/pgadmin/include/schema/pgFunction.h
@@ -93,6 +93,8 @@ public:
     pgObject *Refresh(ctlTree *browser, const wxTreeItemId item);
     wxString GetSelectSql(ctlTree *browser);
 
+    bool ResetStats();
+
 	void ShowHint(frmMain *form, bool force);
 	bool GetCanHint() { return true; };
 
@@ -165,4 +167,13 @@ public:
     wxString GetHelpPage(bool forCreate) const { return wxT("pg/sql-createprocedure"); }
 };
 
+
+class resetFunctionStatsFactory : public contextActionFactory
+{
+public:
+    resetFunctionStatsFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
+    wxWindow *StartDialog(frmMain *form, pgObject *obj);
+    bool CheckEnable(pgObject *obj);
+};
+
 #endif
diff --git a/pgadmin/include/schema/pgTable.h b/pgadmin/include/schema/pgTable.h
index 5626c54..d6c8e7e 100644
--- a/pgadmin/include/schema/pgTable.h
+++ b/pgadmin/include/schema/pgTable.h
@@ -93,6 +93,7 @@ public:
     void UpdateRows();
     bool DropObject(wxFrame *frame, ctlTree *browser, bool cascaded);
     bool Truncate(bool cascaded);
+    bool ResetStats();
     bool CanView() { return true; }
     bool CanMaintenance() { return true; }
     bool CanBackup() { return true; }
@@ -331,4 +332,14 @@ public:
     bool CheckEnable(pgObject *obj);
 };
 
+
+class resetTableStatsFactory : public contextActionFactory
+{
+public:
+    resetTableStatsFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar);
+    wxWindow *StartDialog(frmMain *form, pgObject *obj);
+    bool CheckEnable(pgObject *obj);
+};
+
+
 #endif
diff --git a/pgadmin/schema/pgFunction.cpp b/pgadmin/schema/pgFunction.cpp
index 4d09f08..0243752 100644
--- a/pgadmin/schema/pgFunction.cpp
+++ b/pgadmin/schema/pgFunction.cpp
@@ -18,6 +18,7 @@
 #include "utils/pgfeatures.h"
 #include "utils/misc.h"
 #include "schema/pgFunction.h"
+#include "frm/frmMain.h"
 #include "frm/frmReport.h"
 #include "frm/frmHint.h"
 
@@ -73,6 +74,14 @@ bool pgFunction::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
     return GetDatabase()->ExecuteVoid(sql);
 }
 
+bool pgFunction::ResetStats()
+{
+    wxString sql = wxT("SELECT pg_stat_reset_single_function_counters(")
+      + NumToStr(this->GetOid())
+      + wxT(")");
+    return GetDatabase()->ExecuteVoid(sql);
+}
+
 wxString pgFunction::GetFullName()
 { 
     return GetName() + wxT("(") + GetArgSigList() + wxT(")");
@@ -870,3 +879,27 @@ void pgFunctionCollection::ShowStatistics(frmMain *form, ctlListView *statistics
 		}
     }
 }
+
+
+resetFunctionStatsFactory::resetFunctionStatsFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : contextActionFactory(list)
+{
+    mnu->Append(id, _("&Reset function statistics"),  _("Reset statistics of the selected function."));
+}
+
+
+wxWindow *resetFunctionStatsFactory::StartDialog(frmMain *form, pgObject *obj)
+{
+    if (wxMessageBox(_("Are you sure you wish to reset statistics of this function?"), _("Reset function statistics"), wxYES_NO) == wxNO)
+        return 0;
+
+    ((pgFunction*)obj)->ResetStats();
+    ((pgFunction*)obj)->ShowStatistics(form, form->GetStatistics());
+
+    return 0;
+}
+
+
+bool resetFunctionStatsFactory::CheckEnable(pgObject *obj)
+{
+    return obj && obj->IsCreatedBy(functionFactory) && ((pgFunction*)obj)->GetConnection()->BackendMinimumVersion(9, 0);
+}
diff --git a/pgadmin/schema/pgTable.cpp b/pgadmin/schema/pgTable.cpp
index c38e1b2..52597ef 100644
--- a/pgadmin/schema/pgTable.cpp
+++ b/pgadmin/schema/pgTable.cpp
@@ -160,6 +160,15 @@ bool pgTable::Truncate(bool cascaded)
 }
 
 
+bool pgTable::ResetStats()
+{
+    wxString sql = wxT("SELECT pg_stat_reset_single_table_counters(")
+      + NumToStr(this->GetOid())
+      + wxT(")");
+    return GetDatabase()->ExecuteVoid(sql);
+}
+
+
 void pgTable::AppendStuff(wxString &sql, ctlTree *browser, pgaFactory &factory)
 {
     wxString tmp;
@@ -1693,3 +1702,26 @@ bool truncateCascadedFactory::CheckEnable(pgObject *obj)
     return obj && obj->IsCreatedBy(tableFactory) && ((pgTable*)obj)->GetConnection()->BackendMinimumVersion(8, 2);
 }
 
+
+resetTableStatsFactory::resetTableStatsFactory(menuFactoryList *list, wxMenu *mnu, ctlMenuToolbar *toolbar) : contextActionFactory(list)
+{
+    mnu->Append(id, _("&Reset table statistics"),  _("Reset statistics of the selected table."));
+}
+
+
+wxWindow *resetTableStatsFactory::StartDialog(frmMain *form, pgObject *obj)
+{
+    if (wxMessageBox(_("Are you sure you wish to reset statistics of this table?"), _("Reset statistics"), wxYES_NO) == wxNO)
+        return 0;
+
+    ((pgTable*)obj)->ResetStats();
+    ((pgTable*)obj)->ShowStatistics(form, form->GetStatistics());
+
+    return 0;
+}
+
+
+bool resetTableStatsFactory::CheckEnable(pgObject *obj)
+{
+    return obj && obj->IsCreatedBy(tableFactory) && ((pgTable*)obj)->GetConnection()->BackendMinimumVersion(9, 0);
+}
-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to