Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74f3ee6

Browse files
authored
Merge pull request #705 from utPLSQL/feature/add_pre_install_checks
Added scripts to validate privileges before install.
2 parents 9f7ad6e + e51c424 commit 74f3ee6

3 files changed

Lines changed: 76 additions & 0 deletions

File tree

source/check_object_grants.sql

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
declare
2+
c_expected_grants constant dbmsoutput_linesarray := dbmsoutput_linesarray('DBMS_LOCK','DBMS_CRYPTO');
3+
4+
l_missing_grants varchar2(4000);
5+
6+
function get_view(a_dba_view_name varchar2) return varchar2 is
7+
l_invalid_object_name exception;
8+
l_result varchar2(128) := lower(a_dba_view_name);
9+
pragma exception_init(l_invalid_object_name,-44002);
10+
begin
11+
l_result := dbms_assert.sql_object_name(l_result);
12+
return l_result;
13+
exception
14+
when l_invalid_object_name then
15+
return replace(l_result,'dba_','all_');
16+
end;
17+
18+
begin
19+
execute immediate q'[
20+
select listagg(' - '||object_name,CHR(10)) within group(order by object_name)
21+
from (
22+
select column_value as object_name
23+
from table(:l_expected_grants)
24+
minus
25+
select table_name as object_name
26+
from ]'||get_view('dba_tab_privs')||q'[
27+
where grantee = SYS_CONTEXT('userenv','current_schema')
28+
and owner = 'SYS')]'
29+
into l_missing_grants using c_expected_grants;
30+
if l_missing_grants is not null then
31+
raise_application_error(
32+
-20000
33+
, 'The following object grants are missing for user "'||SYS_CONTEXT('userenv','current_schema')||'" to install utPLSQL:'||CHR(10)
34+
||l_missing_grants||CHR(10)
35+
||'Please read the installation documentation at http://utplsql.org/utPLSQL/'
36+
);
37+
end if;
38+
end;
39+
/
40+

source/check_sys_grants.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
declare
2+
c_expected_grants constant dbmsoutput_linesarray
3+
:= dbmsoutput_linesarray(
4+
'CREATE TYPE','CREATE VIEW','CREATE SYNONYM','CREATE SEQUENCE','CREATE PROCEDURE','CREATE TABLE'
5+
);
6+
7+
l_expected_grants dbmsoutput_linesarray := c_expected_grants;
8+
l_missing_grants varchar2(4000);
9+
begin
10+
if user != SYS_CONTEXT('userenv','current_schema') then
11+
for i in 1 .. l_expected_grants.count loop
12+
l_expected_grants(i) := replace(l_expected_grants(i),' ',' ANY ');
13+
end loop;
14+
end if;
15+
select listagg(' - '||privilege,CHR(10)) within group(order by privilege)
16+
into l_missing_grants
17+
from (
18+
select column_value as privilege
19+
from table(l_expected_grants)
20+
minus
21+
select privilege
22+
from user_sys_privs
23+
);
24+
if l_missing_grants is not null then
25+
raise_application_error(
26+
-20000
27+
, 'The following privileges are required for user "'||user||'" to install into schema "'||SYS_CONTEXT('userenv','current_schema')||'"'||CHR(10)
28+
||l_missing_grants
29+
||'Please read the installation documentation at http://utplsql.org/utPLSQL/'
30+
);
31+
end if;
32+
end;
33+
/

source/install.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ whenever oserror exit failure rollback
2929
prompt Switching current schema to &&ut3_owner
3030
prompt &&line_separator
3131
alter session set current_schema = &&ut3_owner;
32+
33+
@@check_object_grants.sql
34+
@@check_sys_grants.sql
3235
--set define off
3336

3437
--dbms_output buffer cache table

0 commit comments

Comments
 (0)