Fix syntax error when changing the event type for the existing rule. It is a regression of #5115.

Fixes #5215
This commit is contained in:
Aditya Toshniwal 2020-02-24 18:11:31 +05:30 committed by Akshay Joshi
parent 9bad590e9e
commit fd07e0c868
7 changed files with 65 additions and 13 deletions

View File

@ -29,4 +29,5 @@ Bug fixes
| `Issue #5077 <https://redmine.postgresql.org/issues/5077>`_ - Changed background pattern for geometry viewer to use #fff for all themes.
| `Issue #5107 <https://redmine.postgresql.org/issues/5107>`_ - Set proper focus on tab navigation for file manager dialog.
| `Issue #5115 <https://redmine.postgresql.org/issues/5115>`_ - Fix an issue where command and statements were parsed incorrectly for Rules.
| `Issue #5184 <https://redmine.postgresql.org/issues/5184>`_ - Fixed Firefox monospaced issue by updating the font to the latest version.
| `Issue #5184 <https://redmine.postgresql.org/issues/5184>`_ - Fixed Firefox monospaced issue by updating the font to the latest version.
| `Issue #5215 <https://redmine.postgresql.org/issues/5215>`_ - Fix syntax error when changing the event type for the existing rule.

View File

@ -0,0 +1,10 @@
-- Rule: "test_insert_rule1_$%{}[]()&*^!@""'`\/#" ON public.test_emp_rule
-- DROP Rule "test_insert_rule1_$%{}[]()&*^!@""'`\/#" ON public.test_emp_rule;
CREATE OR REPLACE RULE "test_insert_rule1_$%{}[]()&*^!@""'`\/#" AS
ON INSERT TO public.test_emp_rule
WHERE (new.salary > 8000)
DO INSTEAD NOTHING;
COMMENT ON RULE "test_insert_rule1_$%{}[]()&*^!@""'`\/#" ON public.test_emp_rule IS 'This is a insert rule';

View File

@ -0,0 +1,4 @@
CREATE OR REPLACE RULE "test_insert_rule1_$%{}[]()&*^!@""'`\/#" AS
ON INSERT TO public.test_emp_rule
WHERE (new.salary > 8000)
DO INSTEAD NOTHING;

View File

@ -0,0 +1,10 @@
-- Rule: "test_insert_rule1_$%{}[]()&*^!@""'`\/#" ON public.test_emp_rule
-- DROP Rule "test_insert_rule1_$%{}[]()&*^!@""'`\/#" ON public.test_emp_rule;
CREATE OR REPLACE RULE "test_insert_rule1_$%{}[]()&*^!@""'`\/#" AS
ON UPDATE TO public.test_emp_rule
WHERE (new.salary > 8000)
DO INSTEAD NOTHING;
COMMENT ON RULE "test_insert_rule1_$%{}[]()&*^!@""'`\/#" ON public.test_emp_rule IS 'This is a insert rule';

View File

@ -0,0 +1,4 @@
CREATE OR REPLACE RULE "test_insert_rule1_$%{}[]()&*^!@""'`\/#" AS
ON UPDATE TO public.test_emp_rule
WHERE (new.salary > 8000)
DO INSTEAD NOTHING;

View File

@ -33,7 +33,7 @@
"name": "test_insert_rule_$%{}[]()&*^!@\"'`\\/#",
"schema": "public",
"view": "test_emp_rule",
"event": "Insert",
"event": "INSERT",
"condition": "new.salary > 5000",
"statements": "UPDATE test_emp_rule SET salary = 5000\n WHERE test_emp_rule.emp_id = new.emp_id"
},
@ -49,7 +49,7 @@
"name": "test_insert_rule1_$%{}[]()&*^!@\"'`\\/#",
"schema": "public",
"view": "test_emp_rule",
"event": "Insert",
"event": "INSERT",
"do_instead": true,
"comment": "This is a insert rule",
"condition": "new.salary > 8000",
@ -59,7 +59,7 @@
"expected_msql_file": "alter_insert_event_rule_msql.sql"
}, {
"type": "alter",
"name": "Alter Rule for insert event with complex commands",
"name": "Alter Rule insert to update event with complex commands",
"endpoint": "NODE-rule.obj_id",
"sql_endpoint": "NODE-rule.sql_id",
"msql_endpoint": "NODE-rule.msql_id",
@ -68,6 +68,28 @@
},
"expected_sql_file": "alter_insert_event_rule_complex.sql",
"expected_msql_file": "alter_insert_event_rule_complex_msql.sql"
}, {
"type": "alter",
"name": "Alter Rule for insert event to statements NOTHING",
"endpoint": "NODE-rule.obj_id",
"sql_endpoint": "NODE-rule.sql_id",
"msql_endpoint": "NODE-rule.msql_id",
"data": {
"statements": "NOTHING"
},
"expected_sql_file": "alter_insert_event_rule_nothing.sql",
"expected_msql_file": "alter_insert_event_rule_nothing_msql.sql"
}, {
"type": "alter",
"name": "Alter Rule for insert with NOTHING to Update",
"endpoint": "NODE-rule.obj_id",
"sql_endpoint": "NODE-rule.sql_id",
"msql_endpoint": "NODE-rule.msql_id",
"data": {
"event": "UPDATE"
},
"expected_sql_file": "alter_insert_event_rule_nothing_update.sql",
"expected_msql_file": "alter_insert_event_rule_nothing_update_msql.sql"
}, {
"type": "delete",
"name": "Drop Rule",
@ -85,7 +107,7 @@
"name": "test_update_rule_$%{}[]()&*^!@\"'`\\/#",
"schema": "public",
"view": "test_emp_rule",
"event": "Update",
"event": "UPDATE",
"condition": "old.name = 'Joe'",
"statements": "UPDATE test_emp_rule SET salary = new.salary\n WHERE test_emp_rule.name = 'Sam'"
},
@ -101,7 +123,7 @@
"name": "test_update_rule1_$%{}[]()&*^!@\"'`\\/#",
"schema": "public",
"view": "test_emp_rule",
"event": "Update",
"event": "UPDATE",
"do_instead": true,
"comment": "This is a update rule",
"condition": "old.name = 'Sam'",

View File

@ -8,7 +8,7 @@
ALTER RULE {{ conn|qtIdent(o_data.name) }} ON {{ conn|qtIdent(o_data.schema, o_data.view) }} RENAME TO {{ conn|qtIdent(data.name) }};
{% endif %}
{% if data.event or data.do_instead is defined or data.condition is defined or data.statements is defined %}
{% if data.event is defined or data.do_instead is defined or data.condition is defined or data.statements is defined %}
CREATE OR REPLACE RULE {{ conn|qtIdent(rule_name) }} AS
ON {% if data.event and data.event != o_data.event %}{{ data.event|upper }}{% else %}{{ o_data.event|upper }}{% endif %}
TO {{ conn|qtIdent(o_data.schema, o_data.view) }}
@ -18,16 +18,17 @@ CREATE OR REPLACE RULE {{ conn|qtIdent(rule_name) }} AS
WHERE ({{ o_data.condition }})
{% endif %}
DO{% if (('do_instead' not in data and o_data.do_instead in ['true', True]) or (data.do_instead in ['true', True])) %}{{ ' INSTEAD' }}{% endif %}
{% if data.statements and data.statements != o_data.statements and data.statements.strip() in ['', 'NOTHING']%}
{% if data.statements is defined %}
{% if data.statements.strip() in ['', 'NOTHING'] %}
NOTHING;
{% elif data.statements and data.statements != o_data.statements %}
{% else %}
({{ data.statements.rstrip(';') }});
{% elif data.statements is not defined and o_data.statements %}
({{ o_data.statements.rstrip(';') }});
{% else %}
{% endif %}
{% elif o_data.statements.strip() in ['', 'NOTHING'] %}
NOTHING;
{% else %}
({{ o_data.statements.rstrip(';') }});
{% endif %}
{% endif %}