Patch to enable/disable rule on a table
От | Guillaume Lelarge |
---|---|
Тема | Patch to enable/disable rule on a table |
Дата | |
Msg-id | 46FAE0F3.4000006@lelarge.info обсуждение исходный текст |
Ответы |
Re: Patch to enable/disable rule on a table
Re: Patch to enable/disable rule on a table |
Список | pgadmin-hackers |
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(); +}
В списке pgadmin-hackers по дате отправления:
Предыдущее
От: Heikki LinnakangasДата:
Сообщение: Viewing data of a zero-column table gives an assertion failure
Следующее
От: svn@pgadmin.orgДата:
Сообщение: SVN Commit by guillaume: r6677 - in trunk/pgadmin3: docs docs/en_US/hints docs/fi_FI docs/fi_FI/hints i18n/fi_FI