Hi all,
Here is a patch to support this new PostgreSQL 8.3 feature : the
possibility to enable and disable a rule on a table.
Regards.
--
Guillaume.
http://www.postgresqlfr.org
http://dalibo.com
Index: pgadmin/include/schema/pgRule.h
===================================================================
--- pgadmin/include/schema/pgRule.h (révision 6675)
+++ pgadmin/include/schema/pgRule.h (copie de travail)
@@ -61,7 +61,7 @@
bool GetDoInstead() const { return doInstead; }
void iSetDoInstead(const bool b) { doInstead=b; }
bool GetEnabled() const { return enabled; }
- void iSetEnabled(const bool b) { enabled=b; }
+ void iSetEnabled(const bool b);
wxString GetQuotedFullTable() const { return quotedFullTable; }
void iSetQuotedFullTable(const wxString &s) { quotedFullTable=s; }
@@ -79,4 +79,13 @@
bool doInstead, enabled;
};
+class enabledisableRuleFactory : public contextActionFactory
+{
+public:
+ enabledisableRuleFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar);
+ wxWindow *StartDialog(frmMain *form, pgObject *obj);
+ bool CheckEnable(pgObject *obj);
+ bool CheckChecked(pgObject *obj);
+};
+
#endif
Index: pgadmin/frm/frmMain.cpp
===================================================================
--- pgadmin/frm/frmMain.cpp (révision 6675)
+++ pgadmin/frm/frmMain.cpp (copie de travail)
@@ -67,6 +67,7 @@
#include "schema/pgTable.h"
#include "schema/pgIndex.h"
#include "schema/pgTrigger.h"
+#include "schema/pgRule.h"
#include "schema/pgServer.h"
#include "slony/slCluster.h"
#include "slony/slSet.h"
@@ -266,6 +267,7 @@
new enabledisableTriggerFactory(menuFactories, toolsMenu, 0);
new disableAllTriggersFactory(menuFactories, toolsMenu, 0);
new enableAllTriggersFactory(menuFactories, toolsMenu, 0);
+ new enabledisableRuleFactory(menuFactories, toolsMenu, 0);
//--------------------------
new separatorFactory(menuFactories);
Index: pgadmin/schema/pgRule.cpp
===================================================================
--- pgadmin/schema/pgRule.cpp (révision 6675)
+++ pgadmin/schema/pgRule.cpp (copie de travail)
@@ -14,6 +14,7 @@
// App headers
#include "pgAdmin3.h"
+#include "frm/frmMain.h"
#include "utils/misc.h"
#include "schema/pgRule.h"
@@ -36,6 +37,23 @@
}
+void pgRule::iSetEnabled(const bool b)
+ {
+ if (GetQuotedFullTable().Len() > 0 && ((enabled && !b) || (!enabled && b)))
+ {
+ wxString sql = wxT("ALTER TABLE ") + GetQuotedFullTable() + wxT(" ");
+ if (enabled && !b)
+ sql += wxT("DISABLE");
+ else if (!enabled && b)
+ sql += wxT("ENABLE");
+ sql += wxT(" RULE ") + GetQuotedIdentifier();
+ GetDatabase()->ExecuteVoid(sql);
+ }
+
+ enabled=b;
+ }
+
+
wxString pgRule::GetSql(ctlTree *browser)
{
if (sql.IsNull())
@@ -176,3 +194,34 @@
pgRuleFactory ruleFactory;
static pgaCollectionFactory cf(&ruleFactory, __("Rules"), rules_xpm);
+
+
+enabledisableRuleFactory::enabledisableRuleFactory(menuFactoryList *list, wxMenu *mnu, wxToolBar *toolbar) :
contextActionFactory(list)
+{
+ mnu->Append(id, _("Rule enabled?"), _("Enable or disable selected rule."), wxITEM_CHECK);
+}
+
+
+wxWindow *enabledisableRuleFactory::StartDialog(frmMain *form, pgObject *obj)
+{
+ ((pgRule*)obj)->iSetEnabled(!((pgRule*)obj)->GetEnabled());
+
+ wxTreeItemId item=form->GetBrowser()->GetSelection();
+ if (obj == form->GetBrowser()->GetObject(item))
+ obj->ShowTreeDetail(form->GetBrowser(), 0, form->GetProperties());
+ form->GetMenuFactories()->CheckMenu(obj, form->GetMenuBar(), form->GetToolBar());
+
+ return 0;
+}
+
+
+bool enabledisableRuleFactory::CheckEnable(pgObject *obj)
+{
+ return obj && obj->IsCreatedBy(ruleFactory)
+ && ((pgRule*)obj)->GetConnection()->BackendMinimumVersion(8, 3);
+}
+
+bool enabledisableRuleFactory::CheckChecked(pgObject *obj)
+{
+ return obj && obj->IsCreatedBy(ruleFactory) && ((pgRule*)obj)->GetEnabled();
+}