mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Properly format arguments passed by triggers to functions. Fixes #1912
This commit is contained in:
parent
2c85850db1
commit
c345adaa52
@ -3,7 +3,7 @@ SELECT t.oid,t.tgname AS name, t.xmin, t.*, relname, CASE WHEN relkind = 'r' THE
|
|||||||
COALESCE(substring(pg_get_triggerdef(t.oid), 'WHEN (.*) EXECUTE PROCEDURE'),
|
COALESCE(substring(pg_get_triggerdef(t.oid), 'WHEN (.*) EXECUTE PROCEDURE'),
|
||||||
substring(pg_get_triggerdef(t.oid), 'WHEN (.*) \\$trigger')) AS whenclause,
|
substring(pg_get_triggerdef(t.oid), 'WHEN (.*) \\$trigger')) AS whenclause,
|
||||||
-- We need to convert tgargs column bytea datatype to array datatype
|
-- We need to convert tgargs column bytea datatype to array datatype
|
||||||
(string_to_array(encode(tgargs, 'escape'), '\000')::text[])[1:tgnargs] AS tgargs,
|
(string_to_array(encode(tgargs, 'escape'), '\000')::text[])[1:tgnargs] AS custom_tgargs,
|
||||||
{% if datlastsysoid %}
|
{% if datlastsysoid %}
|
||||||
(CASE WHEN t.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_trigger,
|
(CASE WHEN t.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_trigger,
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -470,6 +470,20 @@ class TriggerView(PGChildNodeView):
|
|||||||
|
|
||||||
return data
|
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)
|
||||||
|
|
||||||
|
|
||||||
@check_precondition
|
@check_precondition
|
||||||
def properties(self, gid, sid, did, scid, tid, trid):
|
def properties(self, gid, sid, did, scid, tid, trid):
|
||||||
"""
|
"""
|
||||||
@ -523,10 +537,10 @@ class TriggerView(PGChildNodeView):
|
|||||||
'tfunctions' in result['rows'][0]:
|
'tfunctions' in result['rows'][0]:
|
||||||
data['tfunction'] = result['rows'][0]['tfunctions']
|
data['tfunction'] = result['rows'][0]['tfunctions']
|
||||||
|
|
||||||
if data['tgnargs'] > 1:
|
if data['custom_tgargs'] > 1:
|
||||||
# We know that trigger has more than 1 arguments, let's join them
|
# We know that trigger has more than 1 argument, let's join them
|
||||||
# and convert it as string
|
# and convert it to string
|
||||||
data['tgargs'] = ', '.join(data['tgargs'])
|
data['tgargs'] = self._format_args(data['custom_tgargs'])
|
||||||
|
|
||||||
if len(data['tgattr']) > 1:
|
if len(data['tgattr']) > 1:
|
||||||
columns = ', '.join(data['tgattr'].split(' '))
|
columns = ', '.join(data['tgattr'].split(' '))
|
||||||
@ -770,9 +784,9 @@ class TriggerView(PGChildNodeView):
|
|||||||
self.trigger_name = data['name']
|
self.trigger_name = data['name']
|
||||||
self.lanname = old_data['lanname']
|
self.lanname = old_data['lanname']
|
||||||
|
|
||||||
if old_data['tgnargs'] > 1:
|
if len(old_data['custom_tgargs']) > 1:
|
||||||
# We know that trigger has more than 1 arguments, let's join them
|
# We know that trigger has more than 1 argument, let's join them
|
||||||
old_data['tgargs'] = ', '.join(old_data['tgargs'])
|
old_data['tgargs'] = self._format_args(old_data['custom_tgargs'])
|
||||||
|
|
||||||
if len(old_data['tgattr']) > 1:
|
if len(old_data['tgattr']) > 1:
|
||||||
columns = ', '.join(old_data['tgattr'].split(' '))
|
columns = ', '.join(old_data['tgattr'].split(' '))
|
||||||
@ -827,9 +841,9 @@ class TriggerView(PGChildNodeView):
|
|||||||
data['schema'] = self.schema
|
data['schema'] = self.schema
|
||||||
data['table'] = self.table
|
data['table'] = self.table
|
||||||
|
|
||||||
if data['tgnargs'] > 1:
|
if len(data['custom_tgargs']) > 1:
|
||||||
# We know that trigger has more than 1 arguments, let's join them
|
# We know that trigger has more than 1 argument, let's join them
|
||||||
data['tgargs'] = ', '.join(data['tgargs'])
|
data['tgargs'] = self._format_args(data['custom_tgargs'])
|
||||||
|
|
||||||
if len(data['tgattr']) > 1:
|
if len(data['tgattr']) > 1:
|
||||||
columns = ', '.join(data['tgattr'].split(' '))
|
columns = ', '.join(data['tgattr'].split(' '))
|
||||||
|
Loading…
Reference in New Issue
Block a user