mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Trigger issues through right click. Fixes #1209
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
{### Set a flag which allows us to put OR between events ###}
|
{### Set a flag which allows us to put OR between events ###}
|
||||||
{% set or_flag = False %}
|
{% set or_flag = False %}
|
||||||
|
{% if data.lanname == 'edbspl' or data.tfunction == 'Inline EDB-SPL' %}
|
||||||
|
CREATE OR REPLACE TRIGGER {{ conn|qtIdent(data.name) }}
|
||||||
|
{% else %}
|
||||||
CREATE{% if data.is_constraint_trigger %} CONSTRAINT{% endif %} TRIGGER {{ conn|qtIdent(data.name) }}
|
CREATE{% if data.is_constraint_trigger %} CONSTRAINT{% endif %} TRIGGER {{ conn|qtIdent(data.name) }}
|
||||||
|
{% endif %}
|
||||||
{{data.fires}} {% if data.evnt_insert %}INSERT{% set or_flag = True %}
|
{{data.fires}} {% if data.evnt_insert %}INSERT{% set or_flag = True %}
|
||||||
{% endif %}{% if data.evnt_delete %}
|
{% endif %}{% if data.evnt_delete %}
|
||||||
{% if or_flag %} OR {% endif %}DELETE{% set or_flag = True %}
|
{% if or_flag %} OR {% endif %}DELETE{% set or_flag = True %}
|
||||||
@@ -19,7 +23,8 @@ CREATE{% if data.is_constraint_trigger %} CONSTRAINT{% endif %} TRIGGER {{ conn|
|
|||||||
|
|
||||||
WHEN {{ data.whenclause }}{% endif %}
|
WHEN {{ data.whenclause }}{% endif %}
|
||||||
|
|
||||||
{% if data.code %}{{ data.code }}{% else %}EXECUTE PROCEDURE {{ data.tfunction }}{% if data.tgargs %}({{ data.tgargs }}){% else %}(){% endif%}{% endif%};
|
{% if data.prosrc is defined and
|
||||||
|
(data.lanname == 'edbspl' or data.tfunction == 'Inline EDB-SPL') %}{{ data.prosrc }}{% else %}EXECUTE PROCEDURE {{ data.tfunction }}{% if data.tgargs %}({{ data.tgargs }}){% else %}(){% endif%}{% endif%};
|
||||||
|
|
||||||
{% if data.description %}
|
{% if data.description %}
|
||||||
COMMENT ON TRIGGER {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
|
COMMENT ON TRIGGER {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(data.schema, data.table) }}
|
||||||
|
|||||||
@@ -8,4 +8,8 @@ FROM pg_proc p, pg_namespace n, pg_language l
|
|||||||
{% if not show_system_objects %}
|
{% if not show_system_objects %}
|
||||||
AND (nspname NOT LIKE E'pg\_%' AND nspname NOT in ('information_schema'))
|
AND (nspname NOT LIKE E'pg\_%' AND nspname NOT in ('information_schema'))
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
-- Find function for specific OID
|
||||||
|
{% if tgfoid %}
|
||||||
|
AND p.oid = {{tgfoid}}::OID
|
||||||
|
{% endif %}
|
||||||
ORDER BY nspname ASC, proname ASC
|
ORDER BY nspname ASC, proname ASC
|
||||||
|
|||||||
@@ -1,6 +1,35 @@
|
|||||||
{% if data.name and o_data.name != data.name %}
|
{% if data.name and o_data.name != data.name %}
|
||||||
ALTER TRIGGER {{ conn|qtIdent(o_data.name) }} ON {{ conn|qtIdent(o_data.nspname, o_data.relname) }}
|
ALTER TRIGGER {{ conn|qtIdent(o_data.name) }} ON {{ conn|qtIdent(o_data.nspname, o_data.relname) }}
|
||||||
RENAME TO {{ conn|qtIdent(data.name) }};
|
RENAME TO {{ conn|qtIdent(data.name) }};
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
|
{% if data.prosrc is defined and o_data.lanname == 'edbspl' and o_data.prosrc != data.prosrc %}
|
||||||
|
{% set or_flag = False %}
|
||||||
|
CREATE OR REPLACE TRIGGER {{ conn|qtIdent(data.name) }}
|
||||||
|
{{o_data.fires}} {% if o_data.evnt_insert %}INSERT{% set or_flag = True %}
|
||||||
|
{% endif %}{% if o_data.evnt_delete %}
|
||||||
|
{% if or_flag %} OR {% endif %}DELETE{% set or_flag = True %}
|
||||||
|
{% endif %}{% if o_data.evnt_turncate %}
|
||||||
|
{% if or_flag %} OR {% endif %}TRUNCATE{% set or_flag = True %}
|
||||||
|
{% endif %}{% if o_data.evnt_update %}
|
||||||
|
{% if or_flag %} OR {% endif %}UPDATE {% if o_data.columns|length > 0 %}OF {% for c in o_data.columns %}{% if loop.index != 1 %}, {% endif %}{{ conn|qtIdent(c.column) }}{% endfor %}{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
ON {{ conn|qtIdent(data.schema, data.table) }}
|
||||||
|
{% if o_data.tgdeferrable %}
|
||||||
|
DEFERRABLE{% if o_data.tginitdeferred %} INITIALLY DEFERRED{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
FOR EACH{% if o_data.is_row_trigger %} ROW{% else %} STATEMENT{% endif %}
|
||||||
|
{% if o_data.whenclause %}
|
||||||
|
WHEN {{ o_data.whenclause }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{{ data.prosrc }};
|
||||||
|
|
||||||
|
{% if data.description is not defined and o_data.description %}
|
||||||
|
COMMENT ON TRIGGER {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(o_data.nspname, o_data.relname) }}
|
||||||
|
IS {{o_data.description|qtLiteral}};
|
||||||
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if data.description is defined and o_data.description != data.description %}
|
{% if data.description is defined and o_data.description != data.description %}
|
||||||
COMMENT ON TRIGGER {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(o_data.nspname, o_data.relname) }}
|
COMMENT ON TRIGGER {{ conn|qtIdent(data.name) }} ON {{ conn|qtIdent(o_data.nspname, o_data.relname) }}
|
||||||
|
|||||||
@@ -508,6 +508,26 @@ class TriggerView(PGChildNodeView):
|
|||||||
|
|
||||||
# Making copy of output for future use
|
# Making copy of output for future use
|
||||||
data = dict(res['rows'][0])
|
data = dict(res['rows'][0])
|
||||||
|
|
||||||
|
# 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.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']
|
||||||
|
|
||||||
if data['tgnargs'] > 1:
|
if data['tgnargs'] > 1:
|
||||||
# We know that trigger has more than 1 arguments, let's join them
|
# We know that trigger has more than 1 arguments, let's join them
|
||||||
# and convert it as string
|
# and convert it as string
|
||||||
@@ -673,12 +693,34 @@ class TriggerView(PGChildNodeView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
data['schema'] = self.schema
|
||||||
|
data['table'] = self.table
|
||||||
|
|
||||||
SQL = self.get_sql(scid, tid, trid, data)
|
SQL = self.get_sql(scid, tid, trid, data)
|
||||||
if SQL and SQL.strip('\n') and SQL.strip(' '):
|
if SQL and SQL.strip('\n') and SQL.strip(' '):
|
||||||
status, res = self.conn.execute_scalar(SQL)
|
status, res = self.conn.execute_scalar(SQL)
|
||||||
if not status:
|
if not status:
|
||||||
return internal_server_error(errormsg=res)
|
return internal_server_error(errormsg=res)
|
||||||
|
|
||||||
|
if hasattr(self, 'lanname') and self.lanname == 'edbspl' \
|
||||||
|
and 'prosrc' in data:
|
||||||
|
data['name'] = self.trigger_name
|
||||||
|
SQL = render_template("/".join([self.template_path,
|
||||||
|
'get_oid.sql']),
|
||||||
|
tid=tid, data=data)
|
||||||
|
status, trid = self.conn.execute_scalar(SQL)
|
||||||
|
if not status:
|
||||||
|
return internal_server_error(errormsg=tid)
|
||||||
|
|
||||||
|
return jsonify(
|
||||||
|
node=self.blueprint.generate_browser_node(
|
||||||
|
trid,
|
||||||
|
scid,
|
||||||
|
data['name'],
|
||||||
|
icon="icon-trigger"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
return make_json_response(
|
return make_json_response(
|
||||||
success=1,
|
success=1,
|
||||||
info="Trigger updated",
|
info="Trigger updated",
|
||||||
@@ -758,6 +800,9 @@ class TriggerView(PGChildNodeView):
|
|||||||
if 'name' not in data:
|
if 'name' not in data:
|
||||||
data['name'] = old_data['name']
|
data['name'] = old_data['name']
|
||||||
|
|
||||||
|
self.trigger_name = data['name']
|
||||||
|
self.lanname = old_data['lanname']
|
||||||
|
|
||||||
if old_data['tgnargs'] > 1:
|
if old_data['tgnargs'] > 1:
|
||||||
# We know that trigger has more than 1 arguments, let's join them
|
# We know that trigger has more than 1 arguments, let's join them
|
||||||
old_data['tgargs'] = ', '.join(old_data['tgargs'])
|
old_data['tgargs'] = ', '.join(old_data['tgargs'])
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
label: '{{ _('Trigger') }}',
|
label: '{{ _('Trigger') }}',
|
||||||
hasSQL: true,
|
hasSQL: true,
|
||||||
hasDepends: true,
|
hasDepends: true,
|
||||||
|
width: '650px',
|
||||||
sqlAlterHelp: 'sql-altertrigger.html',
|
sqlAlterHelp: 'sql-altertrigger.html',
|
||||||
sqlCreateHelp: 'sql-createtrigger.html',
|
sqlCreateHelp: 'sql-createtrigger.html',
|
||||||
dialogHelp: '{{ url_for('help.static', filename='trigger_dialog.html') }}',
|
dialogHelp: '{{ url_for('help.static', filename='trigger_dialog.html') }}',
|
||||||
@@ -328,7 +329,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
if(!m.inSchemaWithModelCheck.apply(this, [m])) {
|
if(!m.inSchemaWithModelCheck.apply(this, [m])) {
|
||||||
if(!_.isUndefined(is_constraint_trigger) &&
|
if(!_.isUndefined(is_constraint_trigger) &&
|
||||||
is_constraint_trigger === true) {
|
is_constraint_trigger === true) {
|
||||||
setTimeout(function() { m.set('fires', 'AFTER', {silent: true}) }, 10);
|
setTimeout(function() { m.set('fires', 'AFTER') }, 10);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -419,7 +420,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
id: 'code', label:'{{ _('Code') }}', group: '{{ _('Code') }}',
|
id: 'prosrc', label:'{{ _('Code') }}', group: '{{ _('Code') }}',
|
||||||
type: 'text', mode: ['create', 'edit'], deps: ['tfunction'],
|
type: 'text', mode: ['create', 'edit'], deps: ['tfunction'],
|
||||||
control: 'sql-field', visible: true,
|
control: 'sql-field', visible: true,
|
||||||
disabled: function(m) {
|
disabled: function(m) {
|
||||||
@@ -427,20 +428,14 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
// set to Inline EDB-SPL
|
// set to Inline EDB-SPL
|
||||||
var tfunction = m.get('tfunction'),
|
var tfunction = m.get('tfunction'),
|
||||||
server_type = m.node_info['server']['server_type'];
|
server_type = m.node_info['server']['server_type'];
|
||||||
if(!m.inSchemaWithModelCheck.apply(this, [m])) {
|
|
||||||
if(server_type === 'ppas' &&
|
if(server_type === 'ppas' &&
|
||||||
!_.isUndefined(tfunction) &&
|
!_.isUndefined(tfunction) &&
|
||||||
tfunction === 'Inline EDB-SPL') {
|
tfunction === 'Inline EDB-SPL')
|
||||||
return false;
|
return false;
|
||||||
// Also clear and disable Argument field
|
else
|
||||||
} else {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// Disable it
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},{
|
},{
|
||||||
id: 'is_sys_trigger', label:'{{ _('System trigger?') }}', cell: 'string',
|
id: 'is_sys_trigger', label:'{{ _('System trigger?') }}', cell: 'string',
|
||||||
type: 'switch', disabled: 'inSchemaWithModelCheck', mode: ['properties']
|
type: 'switch', disabled: 'inSchemaWithModelCheck', mode: ['properties']
|
||||||
@@ -476,7 +471,8 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.get('evnt_turncate') && !this.get('evnt_delete') && !this.get('evnt_update') && !this.get('evnt_insert')) {
|
if(!this.get('evnt_turncate') && !this.get('evnt_delete') &&
|
||||||
|
!this.get('evnt_update') && !this.get('evnt_insert')) {
|
||||||
msg = '{{ _('Specify atleast one event.') }}';
|
msg = '{{ _('Specify atleast one event.') }}';
|
||||||
this.errorModel.set('evnt_turncate', " ");
|
this.errorModel.set('evnt_turncate', " ");
|
||||||
this.errorModel.set('evnt_delete', " ");
|
this.errorModel.set('evnt_delete', " ");
|
||||||
@@ -484,6 +480,16 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
|
|||||||
this.errorModel.set('evnt_insert', msg);
|
this.errorModel.set('evnt_insert', msg);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!_.isUndefined(this.get('tfunction')) &&
|
||||||
|
this.get('tfunction') === 'Inline EDB-SPL' &&
|
||||||
|
(_.isUndefined(this.get('prosrc'))
|
||||||
|
|| String(this.get('prosrc')).replace(/^\s+|\s+$/g, '') == ''))
|
||||||
|
{
|
||||||
|
msg = '{{ _('Trigger code can not be empty.') }}';
|
||||||
|
this.errorModel.set('prosrc', msg);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
// We will check if we are under schema node & in 'create' mode
|
// We will check if we are under schema node & in 'create' mode
|
||||||
|
|||||||
@@ -767,7 +767,7 @@ fieldset.inline-fieldset-without-border {
|
|||||||
fieldset.inline-fieldset > legend {
|
fieldset.inline-fieldset > legend {
|
||||||
display: block; border: 0px solid black; box-shadow: none;
|
display: block; border: 0px solid black; box-shadow: none;
|
||||||
box-sizing: content-box; top: auto; bottom: auto; left: auto;
|
box-sizing: content-box; top: auto; bottom: auto; left: auto;
|
||||||
font-size: 16px; font-style: normal; font-weight: 600;
|
font-size: 14px; font-style: normal; font-weight: 600;
|
||||||
height: 20px; line-height: 20px; margin: 0px; padding-bottom: 0px;
|
height: 20px; line-height: 20px; margin: 0px; padding-bottom: 0px;
|
||||||
padding-left: 5px; padding-right: 5px; padding-top: 0px;
|
padding-left: 5px; padding-right: 5px; padding-top: 0px;
|
||||||
vertical-align: middle; width: auto;
|
vertical-align: middle; width: auto;
|
||||||
|
|||||||
Reference in New Issue
Block a user