Hi,
This other patch adds support to the new check_option option of views.
Patch attached, comments welcome.
--
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com
diff --git a/pgadmin/dlg/dlgView.cpp b/pgadmin/dlg/dlgView.cpp
index ca594b5..54765e3 100644
--- a/pgadmin/dlg/dlgView.cpp
+++ b/pgadmin/dlg/dlgView.cpp
@@ -79,18 +79,21 @@
#define txtFillFactor CTRL_TEXT("txtFillFactor")
#define stMatViewWithData CTRL_STATIC("stMatViewWithData")
#define chkMatViewWithData CTRL_CHECKBOX("chkMatViewWithData")
+#define stCheckOption CTRL_STATIC("stCheckOption")
+#define cbCheckOption CTRL_COMBOBOX("cbCheckOption")
BEGIN_EVENT_TABLE(dlgView, dlgSecurityProperty)
EVT_STC_MODIFIED(XRCID("txtSqlBox"), dlgProperty::OnChangeStc)
EVT_CHECKBOX(XRCID("chkSecurityBarrier"), dlgProperty::OnChange)
+ EVT_COMBOBOX(XRCID("cbCheckOption"), dlgProperty::OnChange)
/* Materialized view setting */
- EVT_CHECKBOX(XRCID("chkMaterializedView"), dlgView::OnCheckMaterializedView)
- EVT_TEXT(XRCID("txtFillFactor"), dlgView::OnChangeVacuum)
+ EVT_CHECKBOX(XRCID("chkMaterializedView"), dlgView::OnCheckMaterializedView)
+ EVT_TEXT(XRCID("txtFillFactor"), dlgView::OnChangeVacuum)
- EVT_COMBOBOX(XRCID("cboTablespace"), dlgView::OnChangeVacuum)
+ EVT_COMBOBOX(XRCID("cboTablespace"), dlgView::OnChangeVacuum)
- EVT_CHECKBOX(XRCID("chkMatViewWithData"), dlgProperty::OnChange)
+ EVT_CHECKBOX(XRCID("chkMatViewWithData"), dlgProperty::OnChange)
/* AutoVacuum Settings */
EVT_CHECKBOX(XRCID("chkCustomVac"), dlgView::OnChangeVacuum)
@@ -153,6 +156,7 @@ int dlgView::Go(bool modal)
seclabelPage->Disable();
chkSecurityBarrier->Enable(connection->BackendMinimumVersion(9, 2));
+ cbCheckOption->Enable(connection->BackendMinimumVersion(9, 4));
if (connection->BackendMinimumVersion(9, 3))
{
@@ -350,6 +354,13 @@ int dlgView::Go(bool modal)
// It is not materialized view so disabling all the controls
DisableMaterializedView();
}
+
+ if (view->GetCheckOption().Cmp(wxT("cascaded")) == 0)
+ cbCheckOption->SetSelection(2);
+ else if (view->GetCheckOption().Cmp(wxT("local")) == 0)
+ cbCheckOption->SetSelection(1);
+ else
+ cbCheckOption->SetSelection(0);
}
}
else
@@ -357,6 +368,7 @@ int dlgView::Go(bool modal)
// create mode
cboTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
cboTablespace->SetSelection(0);
+ cbCheckOption->SetSelection(0);
wxCommandEvent ev;
OnChangeVacuum(ev);
}
@@ -428,6 +440,11 @@ void dlgView::CheckChange()
enable = enable || (chkSecurityBarrier->GetValue());
}
}
+
+ if (connection->BackendMinimumVersion(9, 4) && view)
+ {
+ enable = enable || cbCheckOption->GetValue().Lower().Cmp(view->GetCheckOption()) != 0;
+ }
}
EnableOK(enable);
@@ -438,6 +455,7 @@ wxString dlgView::GetSql()
{
wxString sql;
wxString name;
+ wxString withoptions = wxEmptyString;
bool editQuery = false;
if (view)
@@ -502,7 +520,16 @@ wxString dlgView::GetSql()
sql += wxT("CREATE MATERIALIZED VIEW ") + name;
if (connection->BackendMinimumVersion(9, 2) && chkSecurityBarrier->GetValue())
- sql += wxT(" WITH (security_barrier=true)");
+ withoptions += wxT("security_barrier=true");
+ if (connection->BackendMinimumVersion(9, 4))
+ {
+ if (withoptions.Length() > 0)
+ withoptions += wxT(", ");
+ withoptions += wxT("check_option=") + cbCheckOption->GetValue().Lower();
+ }
+
+ if (withoptions.Length() > 0)
+ sql += wxT(" WITH (") + withoptions + wxT(")");
// Add the parameter of tablespace and storage parameter to create the materilized view
if (connection->BackendMinimumVersion(9, 3) && chkMaterializedView->GetValue())
@@ -711,6 +738,19 @@ wxString dlgView::GetSql()
sql += wxT("ALTER VIEW ") + name + wxT("\n SET (security_barrier=false);\n");
}
+ if (connection->BackendMinimumVersion(9, 4)
+ && cbCheckOption->GetValue().Lower().Cmp(view->GetCheckOption()) != 0)
+ {
+ if (cbCheckOption->GetValue().Cmp(wxT("No")) == 0)
+ sql += wxT("ALTER VIEW ") + name + wxT(" RESET (check_option);\n");
+ else
+ sql += wxT("ALTER VIEW ") + name + wxT("\n SET (check_option=") + cbCheckOption->GetValue().Lower() + wxT(");\n");
+ }
+
+ if (withoptions.Length() > 0)
+ sql += wxT(" WITH (") + withoptions + wxT(")");
+
+
if (connection->BackendMinimumVersion(9, 3) && chkMaterializedView->GetValue())
{
if (txtFillFactor->GetValue() != view->GetFillFactor())
diff --git a/pgadmin/include/schema/pgView.h b/pgadmin/include/schema/pgView.h
index dac8d67..7ab908a 100644
--- a/pgadmin/include/schema/pgView.h
+++ b/pgadmin/include/schema/pgView.h
@@ -148,6 +148,15 @@ public:
isPopulated = s;
}
+ wxString GetCheckOption()
+ {
+ return check_option;
+ }
+ void iSetCheckOption(const wxString &s)
+ {
+ check_option = s;
+ }
+
bool GetCustomAutoVacuumEnabled()
{
return !reloptions.IsEmpty();
@@ -358,7 +367,7 @@ private:
toast_autovacuum_vacuum_cost_limit, toast_autovacuum_freeze_min_age,
toast_autovacuum_freeze_max_age, toast_autovacuum_freeze_table_age;
- wxString tablespace, isPopulated;
+ wxString tablespace, isPopulated, check_option;
bool hasToastTable;
OID tablespaceOid;
diff --git a/pgadmin/schema/pgView.cpp b/pgadmin/schema/pgView.cpp
index 5a3e0c5..a7e1b14 100644
--- a/pgadmin/schema/pgView.cpp
+++ b/pgadmin/schema/pgView.cpp
@@ -131,6 +131,8 @@ bool pgView::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
wxString pgView::GetSql(ctlTree *browser)
{
+ wxString withoptions = wxEmptyString;
+
if (sql.IsNull())
{
bool IsMatViewFlag = false;
@@ -141,7 +143,14 @@ wxString pgView::GetSql(ctlTree *browser)
+ wxT("\n\nCREATE OR REPLACE VIEW ") + GetQuotedFullIdentifier();
if (GetConnection()->BackendMinimumVersion(9, 2) && GetSecurityBarrier().Length() > 0)
- sql += wxT(" WITH (security_barrier=") + GetSecurityBarrier() + wxT(")");
+ withoptions += wxT("security_barrier=") + GetSecurityBarrier();
+ if (GetConnection()->BackendMinimumVersion(9, 4) && GetCheckOption().Length() > 0)
+ {
+ if (withoptions.Length() > 0)
+ withoptions += wxT(", ");
+ withoptions += wxT("check_option=") + GetCheckOption();
+ }
+ sql += wxT(" WITH (") + withoptions + wxT(")");
}
else
{
@@ -548,6 +557,9 @@ void pgView::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *proper
properties->AppendItem(_("With data?"), _("No"));
}
+ if (GetConnection()->BackendMinimumVersion(9, 4))
+ properties->AppendItem(_("Check Option"), GetCheckOption());
+
if (!GetLabels().IsEmpty())
{
wxArrayString seclabels = GetProviderLabelArray();
@@ -713,6 +725,11 @@ pgObject *pgViewFactory::CreateObjects(pgCollection *collection, ctlTree *browse
wxT(", c.reloptions AS reloptions, tst.reloptions AS toast_reloptions \n")
wxT(", (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable\n");
}
+ if (collection->GetConnection()->BackendMinimumVersion(9, 4))
+ {
+ sql += wxT(",\nsubstring(array_to_string(c.reloptions, ',') FROM 'check_option=([a-z]*)') AS check_option");
+ }
+
sql += wxT("\n FROM pg_class c\n")
@@ -746,6 +763,10 @@ pgObject *pgViewFactory::CreateObjects(pgCollection *collection, ctlTree *browse
view->iSetAcl(views->GetVal(wxT("relacl")));
view->iSetDefinition(views->GetVal(wxT("definition")));
view->iSetMaterializedView(false);
+ if (collection->GetDatabase()->BackendMinimumVersion(9, 4))
+ {
+ view->iSetCheckOption(views->GetVal(wxT("check_option")));
+ }
if (collection->GetDatabase()->BackendMinimumVersion(9, 1))
{
diff --git a/pgadmin/ui/dlgView.xrc b/pgadmin/ui/dlgView.xrc
index 5e4ed70..0b0f083 100644
--- a/pgadmin/ui/dlgView.xrc
+++ b/pgadmin/ui/dlgView.xrc
@@ -116,7 +116,7 @@
<cols>2</cols>
<vgap>5</vgap>
<hgap>5</hgap>
- <growablerows>1</growablerows>
+ <growablerows>2</growablerows>
<growablecols>1</growablecols>
<object class="sizeritem">
<object class="wxStaticText" name="stSecurityBarrier">
@@ -134,6 +134,25 @@
<border>4</border>
</object>
<object class="sizeritem">
+ <object class="wxStaticText" name="stCheckOption">
+ <label>With Check Option</label>
+ </object>
+ <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
+ <object class="wxComboBox" name="cbCheckOption">
+ <content>
+ <item>No</item>
+ <item>Local</item>
+ <item>Cascaded</item>
+ </content>
+ <style>wxCB_READONLY|wxCB_DROPDOWN</style>
+ </object>
+ <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+ <border>4</border>
+ </object>
+ <object class="sizeritem">
<object class="wxStaticText" name="stDefinition">
<label>Definition</label>
</object>
@@ -706,4 +725,4 @@
</object>
</object>
</object>
-</resource>
\ No newline at end of file
+</resource>
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers