Skip to content

Commit

Permalink
Change the prefix of functions parameters name. Use "p_" instead of "…
Browse files Browse the repository at this point in the history
…v_". This improves the code readability. The end-user may have to change its own scripts if he calls emaj functions using parameter names. The sync_fct_in_upgrade_script.pl tool that builds the functions part of the upgrade script is also ajusted accordingly.
  • Loading branch information
beaud76 committed Dec 28, 2020
1 parent fea2467 commit ef5799b
Show file tree
Hide file tree
Showing 93 changed files with 9,846 additions and 8,898 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ E-Maj - Change log
are imported.
* All E-Maj log objects are now owned by the emaj_adm role (instead of a
superuser).
* Use "p_" instead of "v_" as prefix for functions parameters names. This
may impact user's scripts.
* Coding style improvements.
* Minor code improvements.

Expand Down
2 changes: 1 addition & 1 deletion docs/en/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Coding the *emaj- -devel.sql* script must follow these rules:
* the code is indented with 2 space characters,
* lines must not contain tab characters, must not be longer than 140 characters long and must not end with spaces,
* in the functions structure, the code delimiters must contain the function name surrounded with a $ character (or *$do$* for code blocks),
* variables names are prefixed with *v_* for simple variables or *r_* for *RECORD* type variables,
* variables names are prefixed with *v_* for simple variables, *p_* for functions parameters or *r_* for *RECORD* type variables,
* the code must be compatible with all PostgreSQL versions supported by the current E-Maj version. When this is striclty necessary, the code may be differenciated depending on the PostgreSQL version.

A *perl* script, *tools/check_code.pl* performs some checks on the code format of the script that creates the extension. It also detects unused variables. This script is directly called in non-regression tests scenarios.
Expand Down
4 changes: 2 additions & 2 deletions docs/fr/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Le codage du script emaj- -devel.sql respecte les règles suivantes :
* l’indentation est de 2 caractères espace,
* les lignes ne doivent pas comporter de caractère de tabulation, ne doivent pas dépasser 140 caractères et ne doivent pas se terminer par des espaces,
* dans la structure des fonctions, les délimiteurs du code doivent reprendre le nom de la fonction entouré par un caractère $ (ou *$do$* pour les blocs de code)
* les noms de variables sont préfixés par *v_* pour les variables simples ou *r_* pour les variables de type *RECORD*,
* le code doit être compatible avec toutes les versions de PostgreSQL supportées par la version E-Maj courante. Quand cela s’avére strictement nécessaire, le code peut être différencié en fonction de la version de PostgreSQL.
* les noms de variables sont préfixés par *v_* pour les variables simples, *p_* pour les paramètres des fonctions ou *r_* pour les variables de type *RECORD*,
* le code doit être compatible avec toutes les versions de PostgreSQL supportées par la version E-Maj courante. Quand cela s’avère strictement nécessaire, le code peut être différencié en fonction de la version de PostgreSQL.

Un script perl, *tools/check_code.pl* permet d’effectuer quelques contrôles sur le formatage du script de création de l’extension. Il permet aussi de détecter les variables inutilisées. Ce script est appelé directement dans les scénarios de tests de non régression.

Expand Down
3,498 changes: 2,192 additions & 1,306 deletions sql/emaj--3.4.0--devel.sql

Large diffs are not rendered by default.

2,905 changes: 1,452 additions & 1,453 deletions sql/emaj--devel.sql

Large diffs are not rendered by default.

2,905 changes: 1,452 additions & 1,453 deletions sql/emaj-devel.sql

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions test/10/expected/adm1.out
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ select emaj.emaj_create_group('emptyGroup');
select emaj.emaj_rename_mark_group('myGroup2','EMAJ_LAST_MARK','new_mark_name');
ERROR: _check_mark_name: The group "myGroup2" has no mark.
CONTEXT: PL/pgSQL function emaj._check_mark_name(text[],text,text) line 24 at RAISE
SQL statement "SELECT emaj._check_mark_name(v_groupNames := ARRAY[v_groupName], v_mark := v_mark, v_checkList := '')"
SQL statement "SELECT emaj._check_mark_name(p_groupNames := ARRAY[p_groupName], p_mark := p_mark, p_checkList := '')"
PL/pgSQL function emaj.emaj_rename_mark_group(text,text,text) line 14 at SQL statement
-- force a purge of the history, the alter and the rollback tables
INSERT INTO emaj.emaj_param (param_key, param_value_interval) VALUES ('history_retention','0.1 second'::interval);
Expand All @@ -405,13 +405,13 @@ delete from emaj.emaj_param where param_key = 'history_retention';
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2'],NULL,'EMAJ_LAST_MARK','/dev/null');
ERROR: _check_marks_range: The group "myGroup2" has no mark.
CONTEXT: PL/pgSQL function emaj._check_marks_range(text[],text,text) line 30 at RAISE
SQL statement "SELECT * FROM emaj._check_marks_range(v_groupNames, v_firstMark, v_lastMark)"
SQL statement "SELECT * FROM emaj._check_marks_range(p_groupNames, p_firstMark, p_lastMark)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 42 at SQL statement
PL/pgSQL function emaj.emaj_gen_sql_groups(text[],text,text,text,text[]) line 14 at RETURN
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2','emptyGroup'],NULL,'EMAJ_LAST_MARK','/dev/null');
ERROR: _check_marks_range: The groups "emptyGroup, myGroup2" have no mark.
CONTEXT: PL/pgSQL function emaj._check_marks_range(text[],text,text) line 32 at RAISE
SQL statement "SELECT * FROM emaj._check_marks_range(v_groupNames, v_firstMark, v_lastMark)"
SQL statement "SELECT * FROM emaj._check_marks_range(p_groupNames, p_firstMark, p_lastMark)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 42 at SQL statement
PL/pgSQL function emaj.emaj_gen_sql_groups(text[],text,text,text,text[]) line 14 at RETURN
select emaj.emaj_start_group('myGroup2','M1');
Expand Down Expand Up @@ -2815,57 +2815,57 @@ CONTEXT: PL/pgSQL function emaj.emaj_create_group(text,boolean) line 14 at RAIS
select emaj.emaj_drop_group('dummyGroup');
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := ARRAY[v_groupName], v_mayBeNull := FALSE, v_lockGroups := TRUE, v_checkList := 'IDLE')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := ARRAY[p_groupName], p_mayBeNull := FALSE, p_lockGroups := TRUE, p_checkList := 'IDLE')"
PL/pgSQL function emaj.emaj_drop_group(text) line 12 at PERFORM
select emaj.emaj_force_drop_group('dummyGroup');
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := ARRAY[v_groupName], v_mayBeNull := FALSE, v_lockGroups := TRUE, v_checkList := '')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := ARRAY[p_groupName], p_mayBeNull := FALSE, p_lockGroups := TRUE, p_checkList := '')"
PL/pgSQL function emaj.emaj_force_drop_group(text) line 17 at PERFORM
select emaj.emaj_get_previous_mark_group('dummyGroup', '2010-01-01');
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := ARRAY[v_groupName], v_mayBeNull := FALSE, v_lockGroups := FALSE, v_checkList := '')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := ARRAY[p_groupName], p_mayBeNull := FALSE, p_lockGroups := FALSE, p_checkList := '')"
PL/pgSQL function emaj.emaj_get_previous_mark_group(text,text) line 9 at PERFORM
select emaj.emaj_get_previous_mark_group('dummyGroup', 'EMAJ_LAST_MARK');
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := ARRAY[v_groupName], v_mayBeNull := FALSE, v_lockGroups := FALSE, v_checkList := '')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := ARRAY[p_groupName], p_mayBeNull := FALSE, p_lockGroups := FALSE, p_checkList := '')"
PL/pgSQL function emaj.emaj_get_previous_mark_group(text,text) line 9 at PERFORM
select * from emaj.emaj_log_stat_group('dummyGroup', 'dummyMark', NULL);
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := v_groupNames, v_mayBeNull := v_multiGroup, v_lockGroups := FALSE, v_checkList := '')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := p_groupNames, p_mayBeNull := p_multiGroup, p_lockGroups := FALSE, p_checkList := '')"
PL/pgSQL function emaj._log_stat_groups(text[],boolean,text,text) line 24 at SQL statement
PL/pgSQL function emaj.emaj_log_stat_group(text,text,text) line 7 at RETURN QUERY
select * from emaj.emaj_log_stat_groups(array['dummyGroup'], 'dummyMark', NULL);
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := v_groupNames, v_mayBeNull := v_multiGroup, v_lockGroups := FALSE, v_checkList := '')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := p_groupNames, p_mayBeNull := p_multiGroup, p_lockGroups := FALSE, p_checkList := '')"
PL/pgSQL function emaj._log_stat_groups(text[],boolean,text,text) line 24 at SQL statement
PL/pgSQL function emaj.emaj_log_stat_groups(text[],text,text) line 7 at RETURN QUERY
select * from emaj.emaj_detailed_log_stat_group('dummyGroup', 'dummyMark', NULL);
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := v_groupNames, v_mayBeNull := v_multiGroup, v_lockGroups := FALSE, v_checkList := '')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := p_groupNames, p_mayBeNull := p_multiGroup, p_lockGroups := FALSE, p_checkList := '')"
PL/pgSQL function emaj._detailed_log_stat_groups(text[],boolean,text,text) line 32 at PERFORM
PL/pgSQL function emaj.emaj_detailed_log_stat_group(text,text,text) line 8 at RETURN QUERY
select * from emaj.emaj_detailed_log_stat_groups(array['dummyGroup'],NULL,NULL);
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := v_groupNames, v_mayBeNull := v_multiGroup, v_lockGroups := FALSE, v_checkList := '')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := p_groupNames, p_mayBeNull := p_multiGroup, p_lockGroups := FALSE, p_checkList := '')"
PL/pgSQL function emaj._detailed_log_stat_groups(text[],boolean,text,text) line 32 at PERFORM
PL/pgSQL function emaj.emaj_detailed_log_stat_groups(text[],text,text) line 8 at RETURN QUERY
select emaj.emaj_estimate_rollback_group('dummyGroup', 'dummyMark', TRUE);
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := v_groupNames, v_mayBeNull := v_multiGroup, v_lockGroups := FALSE, v_checkList := '')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := p_groupNames, p_mayBeNull := p_multiGroup, p_lockGroups := FALSE, p_checkList := '')"
PL/pgSQL function emaj._estimate_rollback_groups(text[],boolean,text,boolean) line 17 at SQL statement
PL/pgSQL function emaj.emaj_estimate_rollback_group(text,text,boolean) line 7 at RETURN
select emaj.emaj_estimate_rollback_groups(array['dummyGroup'], 'dummyMark', FALSE);
ERROR: _check_group_names: The group "dummyGroup" does not exist.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 42 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := v_groupNames, v_mayBeNull := v_multiGroup, v_lockGroups := FALSE, v_checkList := '')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := p_groupNames, p_mayBeNull := p_multiGroup, p_lockGroups := FALSE, p_checkList := '')"
PL/pgSQL function emaj._estimate_rollback_groups(text[],boolean,text,boolean) line 17 at SQL statement
PL/pgSQL function emaj.emaj_estimate_rollback_groups(text[],text,boolean) line 7 at RETURN
select * from emaj.emaj_rollback_activity();
Expand Down
30 changes: 15 additions & 15 deletions test/10/expected/adm2.out
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ WARNING: _check_fk_groups: The foreign key "mytbl6_col61_fkey" on the table "my
WARNING: _check_fk_groups: The table "myschema2.mytbl6" is referenced by the foreign key "mytbl8_col81_fkey" on the table "myschema2.mytbl8" that is outside the groups (myGroup1,myGroup2).
ERROR: _check_new_mark: The groups "myGroup1, myGroup2" already contain a mark named "Multi-1".
CONTEXT: PL/pgSQL function emaj._check_new_mark(text[],text) line 31 at RAISE
SQL statement "SELECT emaj._check_new_mark(v_groupNames, v_mark)"
SQL statement "SELECT emaj._check_new_mark(p_groupNames, p_mark)"
PL/pgSQL function emaj._start_groups(text[],text,boolean,boolean) line 44 at SQL statement
PL/pgSQL function emaj.emaj_start_groups(text[],text,boolean) line 11 at RETURN
-- really start both groups
Expand All @@ -98,11 +98,11 @@ WARNING: _check_fk_groups: The table "myschema2.mytbl6" is referenced by the fo
select * from emaj.emaj_rollback_groups(array['myGroup1','myGroup2'],'Multi-1', false);
ERROR: _check_mark_name: For the groups "myGroup1, myGroup2", the mark "Multi-1" is DELETED.
CONTEXT: PL/pgSQL function emaj._check_mark_name(text[],text,text) line 84 at RAISE
SQL statement "SELECT emaj._check_mark_name(v_groupNames := v_groupNames, v_mark := v_mark, v_checkList := 'ACTIVE')"
SQL statement "SELECT emaj._check_mark_name(p_groupNames := p_groupNames, p_mark := p_mark, p_checkList := 'ACTIVE')"
PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 21 at SQL statement
SQL statement "SELECT emaj._rlbk_check(v_groupNames, v_mark, v_isAlterGroupAllowed, FALSE)"
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, p_isAlterGroupAllowed, FALSE)"
PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 23 at SQL statement
SQL statement "SELECT emaj._rlbk_init(v_groupNames, v_mark, v_isLoggedRlbk, 1, v_multiGroup, v_isAlterGroupAllowed)"
SQL statement "SELECT emaj._rlbk_init(p_groupNames, p_mark, p_isLoggedRlbk, 1, p_multiGroup, p_isAlterGroupAllowed)"
PL/pgSQL function emaj._rlbk_groups(text[],text,boolean,boolean,boolean) line 26 at SQL statement
PL/pgSQL function emaj.emaj_rollback_groups(text[],text,boolean) line 8 at RETURN QUERY
-- set again a mark for both groups
Expand Down Expand Up @@ -207,20 +207,20 @@ select emaj.emaj_comment_mark_group('myGroup2','M3','This mark is deleted');
select emaj.emaj_estimate_rollback_group('myGroup2','M3',TRUE);
ERROR: _check_mark_name: For the group "myGroup2", the mark "M3" is DELETED.
CONTEXT: PL/pgSQL function emaj._check_mark_name(text[],text,text) line 81 at RAISE
SQL statement "SELECT emaj._check_mark_name(v_groupNames := v_groupNames, v_mark := v_mark, v_checkList := 'ACTIVE')"
SQL statement "SELECT emaj._check_mark_name(p_groupNames := p_groupNames, p_mark := p_mark, p_checkList := 'ACTIVE')"
PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 21 at SQL statement
SQL statement "SELECT emaj._rlbk_check(v_groupNames, v_mark, TRUE, TRUE)"
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, TRUE, TRUE)"
PL/pgSQL function emaj._estimate_rollback_groups(text[],boolean,text,boolean) line 24 at SQL statement
PL/pgSQL function emaj.emaj_estimate_rollback_group(text,text,boolean) line 7 at RETURN
-- try to rollback on a deleted mark
select * from emaj.emaj_rollback_group('myGroup2','M3',false) order by 1,2;
ERROR: _check_mark_name: For the group "myGroup2", the mark "M3" is DELETED.
CONTEXT: PL/pgSQL function emaj._check_mark_name(text[],text,text) line 81 at RAISE
SQL statement "SELECT emaj._check_mark_name(v_groupNames := v_groupNames, v_mark := v_mark, v_checkList := 'ACTIVE')"
SQL statement "SELECT emaj._check_mark_name(p_groupNames := p_groupNames, p_mark := p_mark, p_checkList := 'ACTIVE')"
PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 21 at SQL statement
SQL statement "SELECT emaj._rlbk_check(v_groupNames, v_mark, v_isAlterGroupAllowed, FALSE)"
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, p_isAlterGroupAllowed, FALSE)"
PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 23 at SQL statement
SQL statement "SELECT emaj._rlbk_init(v_groupNames, v_mark, v_isLoggedRlbk, 1, v_multiGroup, v_isAlterGroupAllowed)"
SQL statement "SELECT emaj._rlbk_init(p_groupNames, p_mark, p_isLoggedRlbk, 1, p_multiGroup, p_isAlterGroupAllowed)"
PL/pgSQL function emaj._rlbk_groups(text[],text,boolean,boolean,boolean) line 26 at SQL statement
PL/pgSQL function emaj.emaj_rollback_group(text,text,boolean) line 7 at RETURN QUERY
-----------------------------
Expand Down Expand Up @@ -1868,12 +1868,12 @@ select emaj.emaj_protect_group('myGroup2');
select * from emaj.emaj_rollback_group('myGroup2','M3',false) order by 1,2;
ERROR: _check_group_names: The group "myGroup2" is currently protected against rollback operations.
CONTEXT: PL/pgSQL function emaj._check_group_names(text[],boolean,boolean,text) line 100 at RAISE
SQL statement "SELECT emaj._check_group_names(v_groupNames := v_groupNames, v_mayBeNull := FALSE, v_lockGroups := TRUE,
v_checkList := 'LOGGING,ROLLBACKABLE,UNPROTECTED')"
SQL statement "SELECT emaj._check_group_names(p_groupNames := p_groupNames, p_mayBeNull := FALSE, p_lockGroups := TRUE,
p_checkList := 'LOGGING,ROLLBACKABLE,UNPROTECTED')"
PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 16 at SQL statement
SQL statement "SELECT emaj._rlbk_check(v_groupNames, v_mark, v_isAlterGroupAllowed, FALSE)"
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, p_isAlterGroupAllowed, FALSE)"
PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 23 at SQL statement
SQL statement "SELECT emaj._rlbk_init(v_groupNames, v_mark, v_isLoggedRlbk, 1, v_multiGroup, v_isAlterGroupAllowed)"
SQL statement "SELECT emaj._rlbk_init(p_groupNames, p_mark, p_isLoggedRlbk, 1, p_multiGroup, p_isAlterGroupAllowed)"
PL/pgSQL function emaj._rlbk_groups(text[],text,boolean,boolean,boolean) line 26 at SQL statement
PL/pgSQL function emaj.emaj_rollback_group(text,text,boolean) line 7 at RETURN QUERY
select emaj.emaj_unprotect_group('myGroup2');
Expand All @@ -1898,9 +1898,9 @@ select emaj.emaj_protect_mark_group('myGroup1','Mark_to_protect');
select * from emaj.emaj_rollback_group('myGroup1','Multi-1',false) order by 1,2;
ERROR: _rlbk_check: Protected marks (Mark_to_protect) for the group "myGroup1" block the rollback to the mark "Multi-1".
CONTEXT: PL/pgSQL function emaj._rlbk_check(text[],text,boolean,boolean) line 41 at RAISE
SQL statement "SELECT emaj._rlbk_check(v_groupNames, v_mark, v_isAlterGroupAllowed, FALSE)"
SQL statement "SELECT emaj._rlbk_check(p_groupNames, p_mark, p_isAlterGroupAllowed, FALSE)"
PL/pgSQL function emaj._rlbk_init(text[],text,boolean,integer,boolean,boolean) line 23 at SQL statement
SQL statement "SELECT emaj._rlbk_init(v_groupNames, v_mark, v_isLoggedRlbk, 1, v_multiGroup, v_isAlterGroupAllowed)"
SQL statement "SELECT emaj._rlbk_init(p_groupNames, p_mark, p_isLoggedRlbk, 1, p_multiGroup, p_isAlterGroupAllowed)"
PL/pgSQL function emaj._rlbk_groups(text[],text,boolean,boolean,boolean) line 26 at SQL statement
PL/pgSQL function emaj.emaj_rollback_group(text,text,boolean) line 7 at RETURN QUERY
select emaj.emaj_unprotect_mark_group('myGroup1','Mark_to_protect');
Expand Down

0 comments on commit ef5799b

Please sign in to comment.