public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][RM3837] Trigger when option syntax error
Date: Mon, 14 Jan 2019 18:25:45 +0530
Message-ID: <CAM9w-_k8ovykJ3ze5pNeTLKZBLrgafG9D0nS9m7jv6dCdBWTXQ@mail.gmail.com> (raw)

Hi Hackers,

Attached is the patch to fix the syntax error if when clause is given.
Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB Software Solutions | Pune
"Don't Complain about Heat, Plant a tree"


Attachments:

  [application/octet-stream] RM3837.patch (5.4K, 3-RM3837.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/10_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/10_plus/properties.sql
index 28d10ad1..12c8c3d3 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/10_plus/properties.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/10_plus/properties.sql
@@ -1,7 +1,6 @@
 SELECT t.oid,t.tgname AS name, t.xmin, t.*, relname, CASE WHEN relkind = 'r' THEN TRUE ELSE FALSE END AS parentistable,
     nspname, des.description, l.lanname, p.prosrc, p.proname AS tfunction,
-    COALESCE(substring(pg_get_triggerdef(t.oid), 'WHEN (.*) EXECUTE PROCEDURE'),
-    substring(pg_get_triggerdef(t.oid), 'WHEN (.*)  \\$trigger')) AS whenclause,
+    pg_catalog.pg_get_expr(t.tgqual, t.tgrelid) AS whenclause
     -- We need to convert tgargs column bytea datatype to array datatype
     (string_to_array(encode(tgargs, 'escape'), E'\\000')::text[])[1:tgnargs] AS custom_tgargs,
 {% if datlastsysoid %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/9.1_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/9.1_plus/properties.sql
index 2d34accf..c1be9c38 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/9.1_plus/properties.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/trigger/sql/9.1_plus/properties.sql
@@ -1,7 +1,6 @@
 SELECT t.oid,t.tgname AS name, t.xmin, t.*, relname, CASE WHEN relkind = 'r' THEN TRUE ELSE FALSE END AS parentistable,
     nspname, des.description, l.lanname, p.prosrc, p.proname AS tfunction,
-    COALESCE(substring(pg_get_triggerdef(t.oid), 'WHEN (.*) EXECUTE PROCEDURE'),
-    substring(pg_get_triggerdef(t.oid), 'WHEN (.*)  \\$trigger')) AS whenclause,
+    pg_catalog.pg_get_expr(t.tgqual, t.tgrelid) AS whenclause,
     -- We need to convert tgargs column bytea datatype to array datatype
     (string_to_array(encode(tgargs, 'escape'), E'\\000')::text[])[1:tgnargs] AS custom_tgargs,
 {% if datlastsysoid %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py
index 7d2b0f11..46cea772 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/__init__.py
@@ -834,6 +834,9 @@ class TriggerView(PGChildNodeView):
         # Adding parent into data dict, will be using it while creating sql
         data['schema'] = self.schema
         data['table'] = self.table
+        # Reverse engineer SQL data has brackets already, hence applying here
+        # to reuse the template sql
+        data['whenclause'] = '(' + data['whenclause'] + ')'
 
         try:
             sql, name = self.get_sql(scid, tid, trid, data)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/static/js/trigger.js b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/static/js/trigger.js
index 7e53254f..2fa66408 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/static/js/trigger.js
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/triggers/static/js/trigger.js
@@ -17,11 +17,10 @@ define('pgadmin.node.trigger', [
   gettext, url_for, $, _, S, pgAdmin, pgBrowser, Backform, alertify,
   SchemaChildTreeNode
 ) {
-
   Backform.CustomSwitchControl = Backform.SwitchControl.extend({
     template: _.template([
-      '<label class="<%=Backform.controlLabelClassName%> custom_switch_label_class"><%=label%></label>',
-      '<div class="<%=Backform.controlsClassName%> custom_switch_control_class">',
+      '<label class="control-label pg-el-sm-6 pg-el-12 custom_switch_label_class"><%=label%></label>',
+      '<div class="pgadmin-controls pg-el-sm-6 pg-el-12 custom_switch_control_class">',
       '  <div class="checkbox">',
       '    <label>',
       '      <input type="checkbox" class="<%=extraClasses.join(\' \')%>"',
@@ -34,7 +33,7 @@ define('pgadmin.node.trigger', [
       '  <span class="<%=Backform.helpMessageClassName%>"><%=helpMessage%></span>',
       '<% } %>',
     ].join('\n')),
-    className: 'pgadmin-control-group form-group col-6',
+    className: 'pgadmin-control-group form-group col-6 row',
   });
 
   if (!pgBrowser.Nodes['coll-trigger']) {
@@ -57,7 +56,7 @@ define('pgadmin.node.trigger', [
       label: gettext('Trigger'),
       hasSQL:  true,
       hasDepends: true,
-      width: '650px',
+      width: pgBrowser.stdW.sm + 'px',
       sqlAlterHelp: 'sql-altertrigger.html',
       sqlCreateHelp: 'sql-createtrigger.html',
       dialogHelp: url_for('help.static', {'filename': 'trigger_dialog.html'}),
@@ -391,7 +390,7 @@ define('pgadmin.node.trigger', [
           },
         },{
           type: 'nested', control: 'fieldset', mode: ['create','edit', 'properties'],
-          label: gettext('Events'), group: gettext('Events'),
+          label: gettext('Events'), group: gettext('Events'), contentClass: 'row',
           schema:[{
             id: 'evnt_insert', label: gettext('INSERT'),
             type: 'switch', mode: ['create','edit', 'properties'],


view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][RM3837] Trigger when option syntax error
  In-Reply-To: <CAM9w-_k8ovykJ3ze5pNeTLKZBLrgafG9D0nS9m7jv6dCdBWTXQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox