Hi,

PFA patch to fix the issue in Table node where it was not displaying
reversed engineered sql for Trigger(s) properly, if trigger function
associated with that trigger has parameters.
RM#2043

--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
diff --git 
a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
 
b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
index 99f0ddc..b80bfd4 100644
--- 
a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
+++ 
b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py
@@ -2132,6 +2132,48 @@ class TableView(PGChildNodeView, DataTypeReader, 
VacuumSettings):
         else:
             return None
 
+    def get_trigger_function_schema(self, data):
+        """
+        This function will return trigger function with schema name
+        """
+        # If language is 'edbspl' then trigger function should be
+        # 'Inline EDB-SPL' else we will find the trigger function
+        # with schema name.
+        if data['lanname'] == 'edbspl':
+            data['tfunction'] = 'Inline EDB-SPL'
+        else:
+            SQL = render_template(
+                "/".join(
+                    [self.trigger_template_path,'get_triggerfunctions.sql']
+                ),
+                tgfoid=data['tgfoid'],
+                show_system_objects=self.blueprint.show_system_objects
+            )
+
+            status, result = self.conn.execute_dict(SQL)
+            if not status:
+                return internal_server_error(errormsg=res)
+
+            # Update the trigger function which we have fetched with
+            # schema name
+            if 'rows' in result and len(result['rows']) > 0 and \
+                            'tfunctions' in result['rows'][0]:
+                data['tfunction'] = result['rows'][0]['tfunctions']
+        return data
+
+    def _format_args(self, args):
+        """
+        This function will format arguments.
+
+        Args:
+            args: Arguments
+
+        Returns:
+            Formated arguments for function
+        """
+        formatted_args = ["'{0}'".format(arg) for arg in args]
+        return ', '.join(formatted_args)
+
     def get_sql(self, did, scid, tid, data):
         """
         This function will generate create/update sql from model data
@@ -2658,9 +2700,11 @@ class TableView(PGChildNodeView, DataTypeReader, 
VacuumSettings):
             data['schema'] = schema
             data['table'] = table
 
-            if data['tgnargs'] > 1:
-                # We know that trigger has more than 1 arguments, let's join 
them
-                data['tgargs'] = ', '.join(data['tgargs'])
+            data = self.get_trigger_function_schema(data)
+
+            if len(data['custom_tgargs']) > 1:
+                # We know that trigger has more than 1 argument, let's join 
them
+                data['tgargs'] = self._format_args(data['custom_tgargs'])
 
             if len(data['tgattr']) > 1:
                 columns = ', '.join(data['tgattr'].split(' '))
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 a3a26d7..5cbcc4d 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
@@ -528,7 +528,7 @@ class TriggerView(PGChildNodeView):
         Returns:
             Formated arguments for function
         """
-        formatted_args = ["{0}".format(arg) for arg in args]
+        formatted_args = ["'{0}'".format(arg) for arg in args]
         return ', '.join(formatted_args)
 
 
-- 
Sent via pgadmin-hackers mailing list (pgadmin-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers

Reply via email to