Hi,

Here is a patch to add the support for this new 8.5 functionality. Ticket is 
http://code.pgadmin.org/trac/ticket/99, commitfest item is 
https://commitfest.postgresql.org/action/patch_view?id=198.

I don't really like the way I get the old WHEN clause, but I don't find 
another way. Another thing that bothers me is the text field: it's one line 
only. Perhaps a bit small?

Comments?


-- 
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com
diff --git a/pgadmin/dlg/dlgTrigger.cpp b/pgadmin/dlg/dlgTrigger.cpp
index daab06a..37c673f 100644
--- a/pgadmin/dlg/dlgTrigger.cpp
+++ b/pgadmin/dlg/dlgTrigger.cpp
@@ -33,6 +33,7 @@
 #define chkUpdate       CTRL_CHECKBOX("chkUpdate")
 #define chkDelete       CTRL_CHECKBOX("chkDelete")
 #define chkTruncate     CTRL_CHECKBOX("chkTruncate")
+#define txtWhen         CTRL_TEXT("txtWhen")
 #define txtBody         CTRL_SQLBOX("txtBody")
 
 BEGIN_EVENT_TABLE(dlgTrigger, dlgProperty)
@@ -45,6 +46,7 @@ BEGIN_EVENT_TABLE(dlgTrigger, dlgProperty)
     EVT_TEXT(XRCID("cbFunction"),                   dlgTrigger::OnChangeFunc)
     EVT_COMBOBOX(XRCID("cbFunction"),               dlgProperty::OnChange)
     EVT_TEXT(XRCID("txtArguments"),                 dlgProperty::OnChange)
+    EVT_TEXT(XRCID("txtWhen"),                      dlgProperty::OnChange)
     EVT_STC_MODIFIED(XRCID("txtBody"),              dlgProperty::OnChangeStc)
 END_EVENT_TABLE();
 
@@ -87,6 +89,7 @@ int dlgTrigger::Go(bool modal)
 		chkTruncate->SetValue((trigger->GetTriggerType() & TRIGGER_TYPE_TRUNCATE) != 0);
         rdbFires->SetSelection(trigger->GetTriggerType() & TRIGGER_TYPE_BEFORE ? 0 : 1);
         txtArguments->SetValue(trigger->GetArguments());
+        txtWhen->SetValue(trigger->GetWhen());
         if (!connection->BackendMinimumVersion(7, 4))
             txtName->Disable();
 
@@ -116,6 +119,8 @@ int dlgTrigger::Go(bool modal)
         }
         else if (!connection->BackendMinimumVersion(8, 4))
 			chkTruncate->Disable();
+        else if (!connection->BackendMinimumVersion(8, 5))
+            txtWhen->Disable();
     }
     else
     {
@@ -220,6 +225,9 @@ wxString dlgTrigger::GetSql()
         else
             sql += wxT("STATEMENT");
 
+        if (connection->BackendMinimumVersion(8, 5) && !txtWhen->GetValue().IsEmpty())
+            sql += wxT("\n   WHEN (") + txtWhen->GetValue() + wxT(")");
+
         if (cbFunction->GetValue() != wxString::Format(wxT("<%s>"), _("Inline EDB-SPL")))
         {
             sql += wxT("\n   EXECUTE PROCEDURE ") + cbFunction->GetValue()
@@ -304,6 +312,7 @@ void dlgTrigger::CheckChange()
                  (txtComment->GetValue() != trigger->GetComment() ||
                  txtName->GetValue() != trigger->GetName() ||
                  (txtBody->GetText() != trigger->GetSource() && cbFunction->GetValue() == wxString::Format(wxT("<%s>"), _("Inline EDB-SPL"))) ||
+                 txtWhen->GetValue() != trigger->GetWhen() ||
                  chkRow->GetValue() != (trigger->GetTriggerType() & TRIGGER_TYPE_ROW ? true : false) ||
                  chkInsert->GetValue() != (trigger->GetTriggerType() & TRIGGER_TYPE_INSERT ? true : false) ||
                  chkUpdate->GetValue() != (trigger->GetTriggerType() & TRIGGER_TYPE_UPDATE ? true : false) ||
diff --git a/pgadmin/include/schema/pgTrigger.h b/pgadmin/include/schema/pgTrigger.h
index 8ff499d..1188d30 100644
--- a/pgadmin/include/schema/pgTrigger.h
+++ b/pgadmin/include/schema/pgTrigger.h
@@ -42,6 +42,8 @@ public:
     void iSetFunction(const wxString& s) { function=s; }
     void iSetArguments(const wxString& s) { arguments=s; }
     wxString GetArguments() const { return arguments; }
+    void iSetWhen(const wxString& s) { when=s; }
+    wxString GetWhen() const { return when; }
     wxString GetLanguage() const { return language; }
     void iSetLanguage(const wxString& s) { language=s; }
     wxString GetSource() const { return source; }
@@ -70,7 +72,7 @@ public:
     bool IsUpToDate();
 
 private:
-    wxString function, quotedFullTable, arguments, language, source;
+    wxString function, quotedFullTable, arguments, when, language, source;
     OID functionOid;
     long triggerType;
     bool enabled;
diff --git a/pgadmin/schema/pgTrigger.cpp b/pgadmin/schema/pgTrigger.cpp
index d082c64..4200f3a 100644
--- a/pgadmin/schema/pgTrigger.cpp
+++ b/pgadmin/schema/pgTrigger.cpp
@@ -100,6 +100,10 @@ wxString pgTrigger::GetSql(ctlTree *browser)
             + wxT("\n  ON ") + GetQuotedFullTable()
             + wxT("\n  FOR EACH ") + GetForEach();
         
+        if (GetConnection()->BackendMinimumVersion(8, 5)
+            && !GetWhen().IsEmpty())
+            sql += wxT("\n  WHEN (") + GetWhen() + wxT(")");
+
         if (GetLanguage() == wxT("edbspl"))
         {
             sql += wxT("\n") + GetSource();
@@ -194,6 +198,8 @@ void pgTrigger::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *pro
         properties->AppendItem(_("For each"), GetForEach());
         if (GetLanguage() != wxT("edbspl"))
             properties->AppendItem(_("Function"), GetFunction() + wxT("(") + GetArguments() + wxT(")"));
+        if (GetConnection()->BackendMinimumVersion(8, 5))
+            properties->AppendItem(_("When?"), GetWhen());
         properties->AppendItem(_("Enabled?"), GetEnabled());
         properties->AppendItem(_("System trigger?"), GetSystemObject());
         properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
@@ -225,7 +231,8 @@ pgObject *pgTriggerFactory::CreateObjects(pgCollection *coll, ctlTree *browser,
     pgTrigger *trigger=0;
 
     wxString trig_sql;
-    trig_sql = wxT("SELECT t.oid, t.xmin, t.*, relname, nspname, des.description, l.lanname, p.prosrc \n")
+    trig_sql = wxT("SELECT t.oid, t.xmin, t.*, relname, nspname, des.description, l.lanname, p.prosrc, \n")
+        wxT("  trim(substring(pg_get_triggerdef(t.oid), 'WHEN (.*) EXECUTE PROCEDURE'), '()') AS whenclause\n")
         wxT("  FROM pg_trigger t\n")
         wxT("  JOIN pg_class cl ON cl.oid=tgrelid\n")
         wxT("  JOIN pg_namespace na ON na.oid=relnamespace\n")
@@ -293,6 +300,9 @@ pgObject *pgTriggerFactory::CreateObjects(pgCollection *coll, ctlTree *browser,
             }
             trigger->iSetArguments(args);
 
+            if (collection->GetDatabase()->connection()->BackendMinimumVersion(8, 5))
+                trigger->iSetWhen(triggers->GetVal(wxT("whenclause")));
+
             if (browser)
             {
                 browser->AppendObject(collection, trigger);
diff --git a/pgadmin/ui/dlgTrigger.xrc b/pgadmin/ui/dlgTrigger.xrc
index 73e4a08..76a6216 100644
--- a/pgadmin/ui/dlgTrigger.xrc
+++ b/pgadmin/ui/dlgTrigger.xrc
@@ -17,10 +17,10 @@
             <object class="wxPanel" name="pnlProperties">
               <object class="wxFlexGridSizer">
                 <cols>2</cols>
-                <rows>9</rows>
+                <rows>10</rows>
                 <vgap>5</vgap>
                 <hgap>5</hgap>
-                <growablerows>7</growablerows>
+                <growablerows>8</growablerows>
                 <growablecols>1</growablecols>
                 <object class="sizeritem">
                   <object class="wxStaticText" name="stName">
@@ -159,6 +159,19 @@
                   </object>
                 </object>
                 <object class="sizeritem">
+                  <object class="wxStaticText" name="stWhen">
+                    <label>When</label>
+                  </object>
+                  <flag>wxALIGN_CENTRE_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
+                  <object class="wxTextCtrl" name="txtWhen">
+                  </object>
+                  <flag>wxEXPAND|wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
+                  <border>4</border>
+                </object>
+                <object class="sizeritem">
                   <object class="wxStaticText" name="stComment">
                     <label>Comment</label>
                   </object>
-- 
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