diff --git a/docs/userguide/install.md b/docs/userguide/install.md index 88e2a2e63..994aa14c0 100644 --- a/docs/userguide/install.md +++ b/docs/userguide/install.md @@ -135,12 +135,13 @@ Example invocation: cd source sqlplus admin/admins_password@database @create_synonyms_and_grants_for_public.sql ut3 ``` -To grant utPLSQL to an individual user, execute script `source/create_synonyms_and_grants_for_user.sql`, provide `schema_name` where utPLSQL is installed and `user_name` to grant access for. +To grant utPLSQL to an individual user, execute scripts `source/create_user_grants.sql` and `source/create_user_synonyms.sql`, provide `schema_name` where utPLSQL is installed and `user_name` to grant access for. Example invocation: ```bash cd source -sqlplus admin/admins_password@database @create_synonyms_and_grants_for_user.sql ut3 hr +sqlplus ut3_user/ut3_password@database @create_user_grants.sql ut3 hr +sqlplus user/user_password@database @create_user_synonyms.sql ut3 hr ``` The following tools that support the SQL*Plus commands can be used to run the installation script: diff --git a/source/core/ut_dbms_output_cache.sql b/source/core/ut_dbms_output_cache.sql index a81f6acbe..91aba0ba5 100644 --- a/source/core/ut_dbms_output_cache.sql +++ b/source/core/ut_dbms_output_cache.sql @@ -1,23 +1,38 @@ -create global temporary table ut_dbms_output_cache( - /* - utPLSQL - Version 3 - Copyright 2016 - 2017 utPLSQL Project - Licensed under the Apache License, Version 2.0 (the "License"): - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - /* - * This table is not a global temporary table as it needs to allow cross-session data exchange - * It is used however as a temporary table with multiple writers. - * This is why it has very high initrans and has nologging - */ - seq_no number(20,0) not null, - text varchar2(4000), - constraint ut_dbms_output_cache_pk primary key(seq_no) -) on commit preserve rows; +/* +utPLSQL - Version 3 +Copyright 2016 - 2017 utPLSQL Project +Licensed under the Apache License, Version 2.0 (the "License"): +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +/* +* This table is not a global temporary table as it needs to allow cross-session data exchange +* It is used however as a temporary table with multiple writers. +* This is why it has very high initrans and has nologging +*/ +declare + l_tab_exist number; +begin + select count(*) into l_tab_exist from + (select table_name from all_tables where table_name = 'UT_DBMS_OUTPUT_CACHE' and owner = sys_context('USERENV','CURRENT_SCHEMA') + union all + select synonym_name from all_synonyms where synonym_name = 'UT_DBMS_OUTPUT_CACHE' and owner = sys_context('USERENV','CURRENT_SCHEMA')); + if l_tab_exist = 0 then + + execute immediate q'[create global temporary table ut_dbms_output_cache + ( + seq_no number(20,0) not null, + text varchar2(4000), + constraint ut_dbms_output_cache_pk primary key(seq_no) + ) on commit preserve rows + ]'; + + end if; +end; +/ diff --git a/source/create_user_grants.sql b/source/create_user_grants.sql new file mode 100644 index 000000000..76406ece9 --- /dev/null +++ b/source/create_user_grants.sql @@ -0,0 +1,120 @@ +/* + utPLSQL - Version 3 + Copyright 2016 - 2017 utPLSQL Project + + Licensed under the Apache License, Version 2.0 (the "License"): + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +Create all necessary grant for the user who owns test packages and want to execute utPLSQL framework +*/ + +@@define_ut3_owner_param.sql + +column 2 new_value 2 noprint +select null as "2" from dual where 1=0; +spool params.sql.tmp +select + case + when '&&2' is null then q'[ACCEPT ut3_user CHAR PROMPT 'Provide schema to which should be granted the utPLSQL v3 ']' + else 'define ut3_user=&&2' + end +from dual; +spool off +set termout on +@params.sql.tmp +set termout off +/* cleanup temporary sql files */ +--try running on windows +$ del params.sql.tmp +--try running on linux/unix +! rm params.sql.tmp +set termout on + +set echo off +set feedback on +set heading off +set verify off + +prompt Granting privileges on UTPLSQL objects in &&ut3_owner schema to user &&ut3_user + +whenever sqlerror exit failure rollback +whenever oserror exit failure rollback + +alter session set current_schema = &&ut3_owner; + +grant execute on &&ut3_owner..ut_be_between to &ut3_user; +grant execute on &&ut3_owner..ut_be_empty to &ut3_user; +grant execute on &&ut3_owner..ut_be_false to &ut3_user; +grant execute on &&ut3_owner..ut_be_greater_or_equal to &ut3_user; +grant execute on &&ut3_owner..ut_be_greater_than to &ut3_user; +grant execute on &&ut3_owner..ut_be_less_or_equal to &ut3_user; +grant execute on &&ut3_owner..ut_be_less_than to &ut3_user; +grant execute on &&ut3_owner..ut_be_like to &ut3_user; +grant execute on &&ut3_owner..ut_be_not_null to &ut3_user; +grant execute on &&ut3_owner..ut_be_null to &ut3_user; +grant execute on &&ut3_owner..ut_be_true to &ut3_user; +grant execute on &&ut3_owner..ut_equal to &ut3_user; +grant execute on &&ut3_owner..ut_have_count to &ut3_user; +grant execute on &&ut3_owner..ut_match to &ut3_user; +grant execute on &&ut3_owner..ut to &ut3_user; +grant execute on &&ut3_owner..ut_runner to &ut3_user; +grant execute on &&ut3_owner..ut_teamcity_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_xunit_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_junit_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_tfs_junit_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_documentation_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_html_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_sonar_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_coveralls_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_cobertura_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_reporters to &ut3_user; +grant execute on &&ut3_owner..ut_varchar2_list to &ut3_user; +grant execute on &&ut3_owner..ut_varchar2_rows to &ut3_user; +grant execute on &&ut3_owner..ut_integer_list to &ut3_user; +grant execute on &&ut3_owner..ut_reporter_base to &ut3_user; +grant execute on &&ut3_owner..ut_output_reporter_base to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_reporter_base to &ut3_user; +grant execute on &&ut3_owner..ut_console_reporter_base to &ut3_user; +grant execute on &&ut3_owner..ut_coverage to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_options to &ut3_user; +grant execute on &&ut3_owner..ut_coverage_helper to &ut3_user; +grant execute on &&ut3_owner..ut_output_buffer_base to &ut3_user; +grant execute on &&ut3_owner..ut_output_table_buffer to &ut3_user; +grant execute on &&ut3_owner..ut_file_mappings to &ut3_user; +grant execute on &&ut3_owner..ut_file_mapping to &ut3_user; +grant execute on &&ut3_owner..ut_file_mapper to &ut3_user; +grant execute on &&ut3_owner..ut_key_value_pairs to &ut3_user; +grant execute on &&ut3_owner..ut_key_value_pair to &ut3_user; +grant select, insert, delete on &&ut3_owner..ut_compound_data_tmp to &ut3_user; +grant select, insert, delete on &&ut3_owner..ut_compound_data_diff_tmp to &ut3_user; +grant execute on &&ut3_owner..ut_sonar_test_reporter to &ut3_user; +grant execute on &&ut3_owner..ut_annotations to &ut3_user; +grant execute on &&ut3_owner..ut_annotation to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_manager to &ut3_user; +grant execute on &&ut3_owner..ut_annotated_object to &ut3_user; +grant execute on &&ut3_owner..ut_annotated_objects to &ut3_user; +grant select on &&ut3_owner..ut_annotation_cache_info to &ut3_user; +grant select on &&ut3_owner..ut_annotation_cache to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_cache_manager to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_parser to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_objs_cache_info to &ut3_user; +grant execute on &&ut3_owner..ut_annotation_obj_cache_info to &ut3_user; +begin + $if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then + execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_blocks to &ut3_user'; + execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_runs to &ut3_user'; + execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_units to &ut3_user'; + $else + null; + $end +end; +/ diff --git a/source/create_synonyms_and_grants_for_user.sql b/source/create_user_synonyms.sql similarity index 59% rename from source/create_synonyms_and_grants_for_user.sql rename to source/create_user_synonyms.sql index 3044cb32f..729ba4002 100644 --- a/source/create_synonyms_and_grants_for_user.sql +++ b/source/create_user_synonyms.sql @@ -51,75 +51,6 @@ whenever oserror exit failure rollback alter session set current_schema = &&ut3_owner; -grant execute on &&ut3_owner..ut_be_between to &ut3_user; -grant execute on &&ut3_owner..ut_be_empty to &ut3_user; -grant execute on &&ut3_owner..ut_be_false to &ut3_user; -grant execute on &&ut3_owner..ut_be_greater_or_equal to &ut3_user; -grant execute on &&ut3_owner..ut_be_greater_than to &ut3_user; -grant execute on &&ut3_owner..ut_be_less_or_equal to &ut3_user; -grant execute on &&ut3_owner..ut_be_less_than to &ut3_user; -grant execute on &&ut3_owner..ut_be_like to &ut3_user; -grant execute on &&ut3_owner..ut_be_not_null to &ut3_user; -grant execute on &&ut3_owner..ut_be_null to &ut3_user; -grant execute on &&ut3_owner..ut_be_true to &ut3_user; -grant execute on &&ut3_owner..ut_equal to &ut3_user; -grant execute on &&ut3_owner..ut_have_count to &ut3_user; -grant execute on &&ut3_owner..ut_match to &ut3_user; -grant execute on &&ut3_owner..ut to &ut3_user; -grant execute on &&ut3_owner..ut_runner to &ut3_user; -grant execute on &&ut3_owner..ut_teamcity_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_xunit_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_junit_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_tfs_junit_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_documentation_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_html_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_sonar_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_coveralls_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_cobertura_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_reporters to &ut3_user; -grant execute on &&ut3_owner..ut_varchar2_list to &ut3_user; -grant execute on &&ut3_owner..ut_varchar2_rows to &ut3_user; -grant execute on &&ut3_owner..ut_integer_list to &ut3_user; -grant execute on &&ut3_owner..ut_reporter_base to &ut3_user; -grant execute on &&ut3_owner..ut_output_reporter_base to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_reporter_base to &ut3_user; -grant execute on &&ut3_owner..ut_console_reporter_base to &ut3_user; -grant execute on &&ut3_owner..ut_coverage to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_options to &ut3_user; -grant execute on &&ut3_owner..ut_coverage_helper to &ut3_user; -grant execute on &&ut3_owner..ut_output_buffer_base to &ut3_user; -grant execute on &&ut3_owner..ut_output_table_buffer to &ut3_user; -grant execute on &&ut3_owner..ut_file_mappings to &ut3_user; -grant execute on &&ut3_owner..ut_file_mapping to &ut3_user; -grant execute on &&ut3_owner..ut_file_mapper to &ut3_user; -grant execute on &&ut3_owner..ut_key_value_pairs to &ut3_user; -grant execute on &&ut3_owner..ut_key_value_pair to &ut3_user; -grant select, insert, delete on &&ut3_owner..ut_compound_data_tmp to &ut3_user; -grant select, insert, delete on &&ut3_owner..ut_compound_data_diff_tmp to &ut3_user; -grant execute on &&ut3_owner..ut_sonar_test_reporter to &ut3_user; -grant execute on &&ut3_owner..ut_annotations to &ut3_user; -grant execute on &&ut3_owner..ut_annotation to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_manager to &ut3_user; -grant execute on &&ut3_owner..ut_annotated_object to &ut3_user; -grant execute on &&ut3_owner..ut_annotated_objects to &ut3_user; -grant select on &&ut3_owner..ut_annotation_cache_info to &ut3_user; -grant select on &&ut3_owner..ut_annotation_cache to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_cache_manager to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_parser to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_objs_cache_info to &ut3_user; -grant execute on &&ut3_owner..ut_annotation_obj_cache_info to &ut3_user; -begin - $if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then - execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_blocks to &ut3_user'; - execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_runs to &ut3_user'; - execute immediate 'grant select, insert, delete, update on &&ut3_owner..dbmspcc_units to &ut3_user'; - $else - null; - $end -end; -/ - - prompt Creating synonyms for UTPLSQL objects in &&ut3_owner schema to user &&ut3_user create or replace synonym &ut3_user..be_between for &&ut3_owner..be_between; diff --git a/source/uninstall.sql b/source/uninstall.sql index c7a04c4d0..7b2ad4f66 100644 --- a/source/uninstall.sql +++ b/source/uninstall.sql @@ -242,7 +242,7 @@ drop type ut_output_buffer_base force; drop view ut_output_buffer_tmp; -drop table ut_output_buffer_tmp$; +drop table ut_output_buffer_tmp$ purge; drop view ut_output_buffer_info_tmp; @@ -274,6 +274,16 @@ drop type ut_varchar2_list force; drop type ut_varchar2_rows force; +drop package ut_coverage_profiler; + +drop package ut_compound_data_helper; + +drop package ut_coverage_helper_profiler; + +drop type ut_have_count; + +drop type ut_compound_data_value; + set echo off set feedback off declare @@ -304,6 +314,71 @@ begin dbms_output.put_line(i||' synonyms dropped'); end; / + +declare + i integer := 0; +begin + dbms_output.put_line('Dropping synonyms pointing to PL/SQL code coverage objects on 12.2 ' || upper('&&ut3_owner')); + for syn in ( + select + case when owner = 'PUBLIC' then 'public synonym ' + else 'synonym ' || owner || '.' + end || synonym_name as syn_name, + table_owner || '.' || table_name as for_object + from all_synonyms s + where 1 = 1 + and table_owner = upper('&&ut3_owner') + and synonym_name in ('DBMSPCC_BLOCKS','DBMSPCC_RUNS','DBMSPCC_UNITS') + ) + loop + + begin + + execute immediate 'drop '||syn.syn_name; + sys.dbms_output.put_line('Dropped '||syn.syn_name||' for object '||syn.for_object); + + i := i + 1; + exception + when others then + sys.dbms_output.put_line('FAILED to drop '||syn.syn_name||' for object '||syn.for_object); + end; + end loop; + sys.dbms_output.put_line('&&line_separator'); + sys.dbms_output.put_line(i||' synonyms dropped'); +end; +/ + +declare + i integer := 0; +begin + sys.dbms_output.put_line('Dropping packages created for 12.2+ ' || upper('&&ut3_owner')); + + for pkg in (select object_name, owner + from all_objects + where 1 = 1 + and owner = upper('&&ut3_owner') + and object_type = 'PACKAGE' + and object_name in ('UT_COVERAGE_HELPER_BLOCK','UT_COVERAGE_BLOCK')) + loop + + begin + execute immediate 'drop package ' || pkg.owner || '.' || pkg.object_name; + + sys.dbms_output.put_line('Dropped '|| pkg.object_name); + i := i + 1; + + exception + when others then + dbms_output.put_line('FAILED to drop ' || pkg.object_name); + end; + + end loop; + + sys.dbms_output.put_line('&&line_separator'); + sys.dbms_output.put_line(i || ' packages dropped'); +end; +/ + begin dbms_output.put_line('&&line_separator'); dbms_output.put_line('Uninstall complete');