Skip to content

Commit

Permalink
Reformat most plpgsql EXECUTE statements in order to use the format()…
Browse files Browse the repository at this point in the history
… function instead of building the SQL statement to execute by concatenating literals and variables. This improves the performance and the security a little bit. Just a few complex EXECUTE statements are left unchanged.
  • Loading branch information
beaud76 committed Jun 29, 2019
1 parent 5e9c380 commit 70c70d5
Show file tree
Hide file tree
Showing 20 changed files with 3,311 additions and 738 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ E-Maj - Change log
<devel>
------
###Enhancements:###

* Minor coding improvements.

###Bug fixes:###
* Fix a bug in the event trigger function that checks table rewrites. When
Expand Down
2,411 changes: 2,411 additions & 0 deletions sql/emaj--3.1.0--devel.sql

Large diffs are not rendered by default.

411 changes: 233 additions & 178 deletions sql/emaj--devel.sql

Large diffs are not rendered by default.

411 changes: 233 additions & 178 deletions sql/emaj-devel.sql

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test/10/expected/create_drop.out
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ERROR: syntax error at or near "dummmy"
LINE 1: ALTER TABLE emaj_myschema1."myTbl3_log" dummmy content
^
QUERY: ALTER TABLE emaj_myschema1."myTbl3_log" dummmy content
CONTEXT: PL/pgSQL function emaj._create_tbl(text,text,text,integer,text,text,bigint,boolean,boolean) line 100 at EXECUTE
CONTEXT: PL/pgSQL function emaj._create_tbl(text,text,text,integer,text,text,bigint,boolean,boolean) line 102 at EXECUTE
SQL statement "SELECT emaj._create_tbl(grpdef_schema, grpdef_tblseq, grpdef_group, grpdef_priority, grpdef_log_dat_tsp, grpdef_log_idx_tsp,
v_timeId, v_isRollbackable, FALSE)
FROM (
Expand Down Expand Up @@ -530,7 +530,7 @@ begin;
create table emaj_myschema1.dummy_log (col1 int);
select emaj.emaj_drop_group('myGroup1');
ERROR: _drop_log_schemas: Cannot drop the schema "emaj_myschema1". It probably owns unattended objects. Use the emaj_verify_all() function to get details.
CONTEXT: PL/pgSQL function emaj._drop_log_schemas(text,boolean) line 33 at RAISE
CONTEXT: PL/pgSQL function emaj._drop_log_schemas(text,boolean) line 35 at RAISE
SQL statement "SELECT emaj._drop_log_schemas(CASE WHEN v_isForced THEN 'FORCE_DROP_GROUP' ELSE 'DROP_GROUP' END, v_isForced)"
PL/pgSQL function emaj._drop_group(text,boolean) line 27 at PERFORM
SQL statement "SELECT emaj._drop_group(v_groupName, FALSE)"
Expand Down
6 changes: 3 additions & 3 deletions test/10/expected/misc.out
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ begin;
savepoint sp1;
select emaj.emaj_stop_group('myGroup2');
ERROR: _stop_groups: The log trigger "emaj_log_trg" on table "myschema2.mytbl4" does not exist any more.
CONTEXT: PL/pgSQL function emaj._stop_groups(text[],text,boolean,boolean) line 92 at RAISE
CONTEXT: PL/pgSQL function emaj._stop_groups(text[],text,boolean,boolean) line 93 at RAISE
PL/pgSQL function emaj.emaj_stop_group(text,text) line 10 at RETURN
rollback to savepoint sp1;
-- the only solution is to change the emaj_group_def table, force the group's stop and recreate or alter the group
Expand Down Expand Up @@ -2012,7 +2012,7 @@ begin;
savepoint sp1;
select emaj.emaj_stop_group('myGroup2');
ERROR: _stop_groups: The truncate trigger "emaj_trunc_trg" on table "myschema2.mytbl4" does not exist any more.
CONTEXT: PL/pgSQL function emaj._stop_groups(text[],text,boolean,boolean) line 104 at RAISE
CONTEXT: PL/pgSQL function emaj._stop_groups(text[],text,boolean,boolean) line 106 at RAISE
PL/pgSQL function emaj.emaj_stop_group(text,text) line 10 at RETURN
rollback to savepoint sp1;
-- the only solution is to change the emaj_group_def table, force the group's stop and recreate or alter the group
Expand Down Expand Up @@ -2124,7 +2124,7 @@ begin;
-- dropping group fails at log schema drop step
select emaj.emaj_drop_group('myGroup1');
ERROR: _drop_log_schemas: Cannot drop the schema "emaj_myschema1". It probably owns unattended objects. Use the emaj_verify_all() function to get details.
CONTEXT: PL/pgSQL function emaj._drop_log_schemas(text,boolean) line 33 at RAISE
CONTEXT: PL/pgSQL function emaj._drop_log_schemas(text,boolean) line 35 at RAISE
SQL statement "SELECT emaj._drop_log_schemas(CASE WHEN v_isForced THEN 'FORCE_DROP_GROUP' ELSE 'DROP_GROUP' END, v_isForced)"
PL/pgSQL function emaj._drop_group(text,boolean) line 27 at PERFORM
SQL statement "SELECT emaj._drop_group(v_groupName, FALSE)"
Expand Down
4 changes: 2 additions & 2 deletions test/11/expected/create_drop.out
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ERROR: syntax error at or near "dummmy"
LINE 1: ALTER TABLE emaj_myschema1."myTbl3_log" dummmy content
^
QUERY: ALTER TABLE emaj_myschema1."myTbl3_log" dummmy content
CONTEXT: PL/pgSQL function emaj._create_tbl(text,text,text,integer,text,text,bigint,boolean,boolean) line 100 at EXECUTE
CONTEXT: PL/pgSQL function emaj._create_tbl(text,text,text,integer,text,text,bigint,boolean,boolean) line 102 at EXECUTE
SQL statement "SELECT emaj._create_tbl(grpdef_schema, grpdef_tblseq, grpdef_group, grpdef_priority, grpdef_log_dat_tsp, grpdef_log_idx_tsp,
v_timeId, v_isRollbackable, FALSE)
FROM (
Expand Down Expand Up @@ -530,7 +530,7 @@ begin;
create table emaj_myschema1.dummy_log (col1 int);
select emaj.emaj_drop_group('myGroup1');
ERROR: _drop_log_schemas: Cannot drop the schema "emaj_myschema1". It probably owns unattended objects. Use the emaj_verify_all() function to get details.
CONTEXT: PL/pgSQL function emaj._drop_log_schemas(text,boolean) line 33 at RAISE
CONTEXT: PL/pgSQL function emaj._drop_log_schemas(text,boolean) line 35 at RAISE
SQL statement "SELECT emaj._drop_log_schemas(CASE WHEN v_isForced THEN 'FORCE_DROP_GROUP' ELSE 'DROP_GROUP' END, v_isForced)"
PL/pgSQL function emaj._drop_group(text,boolean) line 27 at PERFORM
SQL statement "SELECT emaj._drop_group(v_groupName, FALSE)"
Expand Down

0 comments on commit 70c70d5

Please sign in to comment.