Skip to content

Commit

Permalink
In _gen_sql_group(), remove the GRANT on the created temp table (the …
Browse files Browse the repository at this point in the history
…function is not SECURITY DEFINER anymore ... for a while). Also adjust 2 comments in the emaj_gen_sql_group() and emaj_gen_sql_groups() functions.
  • Loading branch information
beaud76 committed Jun 19, 2023
1 parent a8f67bd commit f771006
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 23 deletions.
47 changes: 46 additions & 1 deletion sql/emaj--4.2.0--devel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,52 @@ $emaj_snap_log_group$;
COMMENT ON FUNCTION emaj.emaj_snap_log_group(TEXT,TEXT,TEXT,TEXT,TEXT) IS
$$Snaps all application tables and sequences of an E-Maj group into a given directory.$$;

CREATE OR REPLACE FUNCTION emaj.emaj_gen_sql_group(p_groupName TEXT, p_firstMark TEXT, p_lastMark TEXT, p_location TEXT,
p_tblseqs TEXT[] DEFAULT NULL)
RETURNS BIGINT LANGUAGE plpgsql
SET standard_conforming_strings = ON AS
$emaj_gen_sql_group$
-- This function generates a SQL script representing all updates performed on a tables group between 2 marks.
-- or beetween a mark and the current state. The result is stored into an external file.
-- It calls the _gen_sql_groups() function to effetively process the request.
-- Input: - tables group
-- - start mark
-- - end mark, NULL representing the current state, and 'EMAJ_LAST_MARK' the last set mark for the group
-- - absolute pathname describing the file that will hold the result
-- (may be NULL if the caller reads the temporary table that will hold the script after the function execution)
-- - array of schema qualified table and sequence names to only process those tables and sequences (NULL by default)
-- Output: number of generated SQL statements (non counting comments and transaction management)
BEGIN
-- Call the _gen_sql_groups() function that effectively processes the request.
RETURN emaj._gen_sql_groups(array[p_groupName], FALSE, p_firstMark, p_lastMark, p_location, p_tblseqs);
END;
$emaj_gen_sql_group$;
COMMENT ON FUNCTION emaj.emaj_gen_sql_group(TEXT,TEXT,TEXT,TEXT,TEXT[]) IS
$$Generates a sql script corresponding to all updates performed on a tables group between two marks and stores it into a given file.$$;

CREATE OR REPLACE FUNCTION emaj.emaj_gen_sql_groups(p_groupNames TEXT[], p_firstMark TEXT, p_lastMark TEXT, p_location TEXT,
p_tblseqs TEXT[] DEFAULT NULL)
RETURNS BIGINT LANGUAGE plpgsql
SET standard_conforming_strings = ON AS
$emaj_gen_sql_groups$
-- This function generates a SQL script representing all updates performed on a set of tables groups between 2 marks
-- or beetween a mark and the current state. The result is stored into an external file.
-- It calls the _gen_sql_groups() function to effetively process the request.
-- Input: - tables groups array
-- - start mark
-- - end mark, NULL representing the current state, and 'EMAJ_LAST_MARK' the last set mark for the group
-- - absolute pathname describing the file that will hold the result
-- (may be NULL if the caller reads the temporary table that will hold the script after the function execution)
-- - array of schema qualified table and sequence names to only process those tables and sequences (NULL by default)
-- Output: number of generated SQL statements (non counting comments and transaction management)
BEGIN
-- Call the _gen_sql_groups() function that effectively processes the request.
RETURN emaj._gen_sql_groups(p_groupNames, TRUE, p_firstMark, p_lastMark, p_location, p_tblseqs);
END;
$emaj_gen_sql_groups$;
COMMENT ON FUNCTION emaj.emaj_gen_sql_groups(TEXT[],TEXT,TEXT,TEXT,TEXT[]) IS
$$Generates a sql script replaying all updates performed on a tables groups set between two marks and stores it into a given file.$$;

CREATE OR REPLACE FUNCTION emaj._gen_sql_groups(p_groupNames TEXT[], p_multiGroup BOOLEAN, p_firstMark TEXT, p_lastMark TEXT,
p_location TEXT, p_tblseqs TEXT[])
RETURNS BIGINT LANGUAGE plpgsql
Expand Down Expand Up @@ -2330,7 +2376,6 @@ $_gen_sql_groups$
scr_emaj_txid BIGINT, -- for future use, to insert commit statement at each txid change
scr_sql TEXT -- the generated sql text
);
GRANT SELECT ON emaj_temp_script TO PUBLIC;
-- Test the supplied output file to avoid to discover a bad file name after having spent a lot of time to build the script.
IF p_location IS NOT NULL THEN
PERFORM emaj._copy_to_file('(SELECT 0)', p_location, NULL);
Expand Down
5 changes: 2 additions & 3 deletions sql/emaj--devel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10810,7 +10810,7 @@ $emaj_gen_sql_group$
-- or beetween a mark and the current state. The result is stored into an external file.
-- It calls the _gen_sql_groups() function to effetively process the request.
-- Input: - tables group
-- - start mark, NULL representing the first mark
-- - start mark
-- - end mark, NULL representing the current state, and 'EMAJ_LAST_MARK' the last set mark for the group
-- - absolute pathname describing the file that will hold the result
-- (may be NULL if the caller reads the temporary table that will hold the script after the function execution)
Expand All @@ -10833,7 +10833,7 @@ $emaj_gen_sql_groups$
-- or beetween a mark and the current state. The result is stored into an external file.
-- It calls the _gen_sql_groups() function to effetively process the request.
-- Input: - tables groups array
-- - start mark, NULL representing the first mark
-- - start mark
-- - end mark, NULL representing the current state, and 'EMAJ_LAST_MARK' the last set mark for the group
-- - absolute pathname describing the file that will hold the result
-- (may be NULL if the caller reads the temporary table that will hold the script after the function execution)
Expand Down Expand Up @@ -10952,7 +10952,6 @@ $_gen_sql_groups$
scr_emaj_txid BIGINT, -- for future use, to insert commit statement at each txid change
scr_sql TEXT -- the generated sql text
);
GRANT SELECT ON emaj_temp_script TO PUBLIC;
-- Test the supplied output file to avoid to discover a bad file name after having spent a lot of time to build the script.
IF p_location IS NOT NULL THEN
PERFORM emaj._copy_to_file('(SELECT 0)', p_location, NULL);
Expand Down
5 changes: 2 additions & 3 deletions sql/emaj-devel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10817,7 +10817,7 @@ $emaj_gen_sql_group$
-- or beetween a mark and the current state. The result is stored into an external file.
-- It calls the _gen_sql_groups() function to effetively process the request.
-- Input: - tables group
-- - start mark, NULL representing the first mark
-- - start mark
-- - end mark, NULL representing the current state, and 'EMAJ_LAST_MARK' the last set mark for the group
-- - absolute pathname describing the file that will hold the result
-- (may be NULL if the caller reads the temporary table that will hold the script after the function execution)
Expand All @@ -10840,7 +10840,7 @@ $emaj_gen_sql_groups$
-- or beetween a mark and the current state. The result is stored into an external file.
-- It calls the _gen_sql_groups() function to effetively process the request.
-- Input: - tables groups array
-- - start mark, NULL representing the first mark
-- - start mark
-- - end mark, NULL representing the current state, and 'EMAJ_LAST_MARK' the last set mark for the group
-- - absolute pathname describing the file that will hold the result
-- (may be NULL if the caller reads the temporary table that will hold the script after the function execution)
Expand Down Expand Up @@ -10959,7 +10959,6 @@ $_gen_sql_groups$
scr_emaj_txid BIGINT, -- for future use, to insert commit statement at each txid change
scr_sql TEXT -- the generated sql text
);
GRANT SELECT ON emaj_temp_script TO PUBLIC;
-- Test the supplied output file to avoid to discover a bad file name after having spent a lot of time to build the script.
IF p_location IS NOT NULL THEN
PERFORM emaj._copy_to_file('(SELECT 0)', p_location, NULL);
Expand Down
4 changes: 2 additions & 2 deletions test/11/expected/misc.out
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_group(text,text,text,text,text[]) line 14 at RETURN
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2'], 'Multi-1', NULL, '/tmp/unknownDirectory/myFile');
NOTICE: table "emaj_temp_script" does not exist, skipping
Expand All @@ -1289,7 +1289,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_groups(text[],text,text,text,text[]) line 14 at RETURN
-- should be ok
-- generated files content is checked later in adm2.sql scenario
Expand Down
4 changes: 2 additions & 2 deletions test/12/expected/misc.out
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_group(text,text,text,text,text[]) line 14 at RETURN
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2'], 'Multi-1', NULL, '/tmp/unknownDirectory/myFile');
NOTICE: table "emaj_temp_script" does not exist, skipping
Expand All @@ -1289,7 +1289,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_groups(text[],text,text,text,text[]) line 14 at RETURN
-- should be ok
-- generated files content is checked later in adm2.sql scenario
Expand Down
4 changes: 2 additions & 2 deletions test/13/expected/misc.out
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_group(text,text,text,text,text[]) line 14 at RETURN
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2'], 'Multi-1', NULL, '/tmp/unknownDirectory/myFile');
NOTICE: table "emaj_temp_script" does not exist, skipping
Expand All @@ -1289,7 +1289,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_groups(text[],text,text,text,text[]) line 14 at RETURN
-- should be ok
-- generated files content is checked later in adm2.sql scenario
Expand Down
7 changes: 3 additions & 4 deletions test/14/expected/install_psql.out
Original file line number Diff line number Diff line change
Expand Up @@ -10619,7 +10619,7 @@ $emaj_gen_sql_group$
-- or beetween a mark and the current state. The result is stored into an external file.
-- It calls the _gen_sql_groups() function to effetively process the request.
-- Input: - tables group
-- - start mark, NULL representing the first mark
-- - start mark
-- - end mark, NULL representing the current state, and 'EMAJ_LAST_MARK' the last set mark for the group
-- - absolute pathname describing the file that will hold the result
-- (may be NULL if the caller reads the temporary table that will hold the script after the function execution)
Expand All @@ -10641,7 +10641,7 @@ $emaj_gen_sql_groups$
-- or beetween a mark and the current state. The result is stored into an external file.
-- It calls the _gen_sql_groups() function to effetively process the request.
-- Input: - tables groups array
-- - start mark, NULL representing the first mark
-- - start mark
-- - end mark, NULL representing the current state, and 'EMAJ_LAST_MARK' the last set mark for the group
-- - absolute pathname describing the file that will hold the result
-- (may be NULL if the caller reads the temporary table that will hold the script after the function execution)
Expand Down Expand Up @@ -10759,7 +10759,6 @@ $_gen_sql_groups$
scr_emaj_txid BIGINT, -- for future use, to insert commit statement at each txid change
scr_sql TEXT -- the generated sql text
);
GRANT SELECT ON emaj_temp_script TO PUBLIC;
-- Test the supplied output file to avoid to discover a bad file name after having spent a lot of time to build the script.
IF p_location IS NOT NULL THEN
PERFORM emaj._copy_to_file('(SELECT 0)', p_location, NULL);
Expand Down Expand Up @@ -12390,7 +12389,7 @@ $do$
RETURN;
END;
$do$;
psql:sql/emaj-devel.sql:12631: NOTICE: E-Maj installation: E-Maj successfully installed.
psql:sql/emaj-devel.sql:12630: NOTICE: E-Maj installation: E-Maj successfully installed.
COMMIT;
-- Test the dblink extension lack (this cannot be easily simulated in the verify.sql unit tests script when emaj is installed as an extension)
begin;
Expand Down
4 changes: 2 additions & 2 deletions test/14/expected/misc.out
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_group(text,text,text,text,text[]) line 14 at RETURN
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2'], 'Multi-1', NULL, '/tmp/unknownDirectory/myFile');
NOTICE: table "emaj_temp_script" does not exist, skipping
Expand All @@ -1331,7 +1331,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_groups(text[],text,text,text,text[]) line 14 at RETURN
-- should be ok
-- generated files content is checked later in adm2.sql scenario
Expand Down
4 changes: 2 additions & 2 deletions test/15/expected/misc.out
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_group(text,text,text,text,text[]) line 14 at RETURN
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2'], 'Multi-1', NULL, '/tmp/unknownDirectory/myFile');
NOTICE: table "emaj_temp_script" does not exist, skipping
Expand All @@ -1331,7 +1331,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_groups(text[],text,text,text,text[]) line 14 at RETURN
-- should be ok
-- generated files content is checked later in adm2.sql scenario
Expand Down
4 changes: 2 additions & 2 deletions test/16/expected/misc.out
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_group(text,text,text,text,text[]) line 14 at RETURN
select emaj.emaj_gen_sql_groups(array['myGroup1','myGroup2'], 'Multi-1', NULL, '/tmp/unknownDirectory/myFile');
NOTICE: table "emaj_temp_script" does not exist, skipping
Expand All @@ -1331,7 +1331,7 @@ HINT: COPY TO instructs the PostgreSQL server process to write a file. You may
CONTEXT: SQL statement "COPY (SELECT 0) TO '/tmp/unknownDirectory/myFile' "
PL/pgSQL function emaj._copy_to_file(text,text,text) line 20 at EXECUTE
SQL statement "SELECT emaj._copy_to_file('(SELECT 0)', p_location, NULL)"
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 105 at PERFORM
PL/pgSQL function emaj._gen_sql_groups(text[],boolean,text,text,text,text[]) line 104 at PERFORM
PL/pgSQL function emaj.emaj_gen_sql_groups(text[],text,text,text,text[]) line 14 at RETURN
-- should be ok
-- generated files content is checked later in adm2.sql scenario
Expand Down

0 comments on commit f771006

Please sign in to comment.