MINI MINI MANI MO
Rem
Rem $Header: sdo/admin/semvalidatei.sql /main/23 2017/09/15 06:48:22 matperry Exp $
Rem
Rem semvalidatei.sql
Rem
Rem Copyright (c) 2012, 2017, Oracle and/or its affiliates.
Rem All rights reserved.
Rem
Rem NAME
Rem semvalidatei.sql - <one-line expansion of the name>
Rem
Rem DESCRIPTION
Rem <short description of component this file declares/defines>
Rem
Rem NOTES
Rem <other useful comments, qualifications, etc.>
Rem
Rem BEGIN SQL_FILE_METADATA
Rem SQL_SOURCE_FILE: sdo/admin/semvalidatei.sql
Rem SQL_SHIPPED_FILE: md/admin/semvalidatei.sql
Rem SQL_PHASE: UPGRADE
Rem SQL_STARTUP_MODE: NORMAL
Rem SQL_IGNORABLE_ERRORS: NONE
Rem SQL_CALLING_FILE: sdo/admin/semvalidate.sql
Rem END SQL_FILE_METADATA
Rem
Rem MODIFIED (MM/DD/YY)
Rem matperry 09/12/17 - update sem_version for 18.1
Rem rjanders 06/30/17 - Add SYS/MDSYS prefixes
Rem echong 06/27/17 - subpartitioning support
Rem rjanders 05/10/17 - #26037683: Raise 'when other' exceptions
Rem rjanders 04/27/17 - Correct "SQL_PHASE" metadata values
Rem rjanders 03/23/17 - #25437999: Remove 'when others then NULL'
Rem handlers
Rem rjanders 03/10/17 - Add missing SQL_FILE_METADATA information
Rem matperry 03/07/17 - update sem_version for 12.2.0.2.0
Rem sravada 01/11/17 - bug 25370681
Rem anestrad 02/26/16 - Check migration status in RDF_PARAMETER
Rem matperry 01/11/16 - set status to INVALID is VPD or WM is being used
Rem matperry 12/03/15 - update sem_version for 12.2.0.1.0
Rem matperry 06/10/15 - remove enableGeoRaster because this has been
Rem replaced with a separate trigger
Rem matperry 01/15/15 - run MDSYS.enableGeoRaster so that truncate
Rem trigger works
Rem rjanders 01/02/15 - long identifier project phase 1
Rem matperry 03/13/14 - update for pg_match
Rem matperry 02/21/14 - add query to rdfctx_policies$ to validate the
Rem table
Rem matperry 11/18/13 - update sem_version for 12.1.0.2.0
Rem matperry 11/08/13 - check status of unique PCSGM index when setting
Rem installation validity
Rem rjanders 09/16/13 - OCCS: Remove hardtabs
Rem rjanders 03/15/13 - #16473696: Start/End _ORACLE_SCRIPT
Rem initialization
Rem matperry 07/06/12 - Created
Rem
Rem ********************************************************************
Rem #16473696: Indicate Oracle-Supplied object
@@?/rdbms/admin/sqlsessstart.sql
Rem ********************************************************************
--------------------------------------------------------------------------
-- semvalidate internal: called by SDO scripts. Does not alter session --
-- to set current_schema to SYS when exiting, which avoids potentially --
-- messing up subsequent SDO scripts. --
--------------------------------------------------------------------------
-- recompile any invalid objects --
declare
num_invalid number;
invalid_data number;
invalid_idx number;
sem_version_exists number;
obj varchar2(130);
otype varchar2(19);
type cursor_type is REF CURSOR;
query_crs cursor_type ;
stmt varchar2(2000);
rdf_param_exists number;
link_exists number;
pcsgm_exists number;
pcsgm_invalid number;
subp_cnt number;
wm_used number;
vpd_used number;
need_mig number;
table_not_found exception;
pragma exception_init(table_not_found, -00942);
object_not_found exception;
pragma exception_init(object_not_found, -04043);
compile_errors exception;
pragma exception_init(compile_errors, -24344);
begin
-- query RDFCTX_POLICIES$ to avoid the table being invalid when
-- checking for validity
begin
execute immediate 'select count(*) from MDSYS.RDFCTX_POLICIES$';
exception
-- ignore table does not exist exceptions
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: query RDFCTX_POLICIES$: '||SQLERRM);
-- RAISE;
end;
-- try to compile any invalid objects --
stmt :=
'select
OBJECT_NAME, OBJECT_TYPE
from
SYS.all_objects
where OWNER = ''MDSYS''
and status=''INVALID''
and (
object_name like ''RDF_%'' or
object_name like ''SDO_RDF%'' or
object_name like ''SDO_SEM%'' or
object_name like ''SEM_%'' or
object_name like ''SEMR_%'' or
object_name like ''RDFR_%'' or
object_name like ''WM$%'' or
object_name like ''WMLT$%'' or
object_name like ''SPARQL_%'' or
object_name like ''PG_%'' or
object_name like ''SDO_PG_%'' or
object_name = ''PRLLIDX_CREATE''
)';
open query_crs for stmt;
loop
begin
fetch query_crs into obj, otype;
exit when query_crs%NOTFOUND ;
begin
if (otype = 'PACKAGE BODY') then
obj := sys.dbms_assert.enquote_name(obj,FALSE);
execute immediate ' alter package '|| obj ||' compile body';
elsif (otype = 'TYPE BODY') then
obj := sys.dbms_assert.enquote_name(obj,FALSE);
execute immediate ' alter type '|| obj ||' compile body';
elsif (otype = 'TRIGGER') then
obj := sys.dbms_assert.enquote_name(obj,FALSE);
execute immediate ' alter trigger '|| obj ||' compile';
elsif (otype = 'VIEW') then
obj := sys.dbms_assert.enquote_name(obj,FALSE);
execute immediate ' alter view '|| obj ||' compile';
elsif (otype = 'INDEXTYPE') then
obj := sys.dbms_assert.enquote_name(obj,FALSE);
execute immediate ' alter indextype '|| obj ||' compile';
elsif (otype = 'OPERATOR') then
obj := sys.dbms_assert.enquote_name(obj,FALSE);
execute immediate ' alter operator '|| obj ||' compile';
elsif (otype = 'PROCEDURE') then
obj := sys.dbms_assert.enquote_name(obj,FALSE);
execute immediate ' alter procedure '|| obj ||' compile';
else
null; -- no action for now
end if;
exception
when object_not_found then NULL;
when compile_errors then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: compile: '||SQLERRM);
-- RAISE;
end;
commit;
end;
end loop;
close query_crs;
-- now do check for validity --
-- see if there are any invalid sem objects --
-- RDFOLS_SECUREACCESS trigger will be invalid if OLS is disabled
-- this should not affect overall validity of the installation
select count(*) into num_invalid
from SYS.all_objects
where OWNER = 'MDSYS'
and status = 'INVALID'
and (
object_name like 'RDF_%' or
object_name like 'SDO_RDF%' or
object_name like 'SDO_SEM%' or
object_name like 'SEM_%' or
object_name like 'SEMR_%' or
object_name like 'RDFR_%'
)
and object_name <> 'RDFOLS_SECUREACCESS';
-- validity also depends on data migration --
-- see if semantic data is valid --
begin
execute immediate
'select count(*)
from
mdsys.rdf_parameter
where ( namespace = ''MDSYS'' and value = ''INVALID'' and
attribute IN (''FLOAT_DOUBLE_DECIMAL'', ''NULL_LITERAL'',
''XSD_TIME'', ''XSD_BOOLEAN'') )
or
( namespace = ''MDSYS'' and
value IN (''FAILED_UNABLE_TO_LOCK_APPLICATION_TABLES'',
''FAILED_INSUFFICIENT_WORKSPACE_PRIVILEGES'',
''FAILED_OLS_POLICIES_ARE_ENABLED'') and
attribute = ''DATA_CONVERSION_CHECK'' )'
into invalid_data;
exception
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: check data validity: '||SQLERRM);
-- RAISE;
end;
-- check for a valid PCSGM index --
begin
-- get rid of any index invalid rows before checking
begin
execute immediate
'delete
from
mdsys.rdf_parameter
where namespace = ''MDSYS'' and value = ''INVALID'' and
attribute IN (''PCSGM_INDEX_STATUS'')';
exception
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: delete pre-existing PCSGM status rows: '||SQLERRM);
-- RAISE;
end;
-- check for existing RDF_LINK$ table
begin
execute immediate
'select count(*)
from SYS.all_tables
where owner = ''MDSYS'' and table_name = ''RDF_LINK$'''
into link_exists;
exception
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: checking for RDF_LINK$ table: '||SQLERRM);
-- RAISE;
end;
-- if RDF_LINK$ exists, then make sure unique index is valid --
if (link_exists > 0) then
-- step 1: make sure unique PCSGM or PCSGML index exists
begin
execute immediate
'select count(*)
from SYS.all_indexes
where owner = ''MDSYS'' and
table_name = ''RDF_LINK$'' and
index_name IN (''RDF_LNK_PCSGM_IDX'',''RDF_LNK_PCSGML_IDX'') and
uniqueness = ''UNIQUE'''
into pcsgm_exists;
exception
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: checking for PCSGM_IDX existence: '||SQLERRM);
-- RAISE;
end;
-- step 2: if index exists, make sure there are no invalid partitions
if (pcsgm_exists > 0) then
begin
select def_subpartition_count into subp_cnt from all_part_tables
where owner='MDSYS' and table_name='RDF_LINK$';
if (subp_cnt > 0) then
select count(*) into pcsgm_invalid
from SYS.all_indexes ai,
all_ind_subpartitions ip
where ai.owner = 'MDSYS' and
ai.table_name = 'RDF_LINK$' and
ai.index_name IN ('RDF_LNK_PCSGM_IDX','RDF_LNK_PCSGML_IDX') and
ai.index_name = ip.index_name and
ai.owner = ip.index_owner and
ip.status <> 'USABLE';
else
execute immediate
'select count(*)
from SYS.all_indexes ai,
SYS.all_ind_partitions ip
where ai.owner = ''MDSYS'' and
ai.table_name = ''RDF_LINK$'' and
ai.index_name IN (''RDF_LNK_PCSGM_IDX'',''RDF_LNK_PCSGML_IDX'') and
ai.index_name = ip.index_name and
ai.owner = ip.index_owner and
ip.status <> ''USABLE'''
into pcsgm_invalid;
end if;
exception
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: checking for PCSGM_IDX status: '||SQLERRM);
-- RAISE;
end;
-- set status to invalid if there is a PCSGM_IDX partition with invalid status
if (pcsgm_invalid > 0) then
begin
execute immediate
'insert into mdsys.rdf_parameter (namespace, attribute, value, description)
values (''MDSYS'', ''PCSGM_INDEX_STATUS'', ''INVALID'', ''Index not USABLE'')';
exception
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: setting PCSGM_IDX status: '||SQLERRM);
-- RAISE;
end;
end if;
-- step 1 failed, set status to invalid
else
begin
execute immediate
'insert into mdsys.rdf_parameter (namespace, attribute, value, description)
values (''MDSYS'', ''PCSGM_INDEX_STATUS'', ''INVALID'', ''Index missing'')';
exception
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: setting PCSGM_IDX status: '||SQLERRM);
-- RAISE;
end;
end if;
end if;
commit;
end;
-- see if WM or VPD is being used
-- WM
begin
execute immediate
'select count(*) from mdsys.rdf_parameter
where namespace = :1 and attribute = :2'
into wm_used
using 'COMPONENT','RDFOWM';
if (wm_used > 0) then
-- set status to INVALID
execute immediate
'update mdsys.rdf_parameter
set description = :1
where namespace = :2 and attribute = :3'
using 'Feature not supported in current version',
'COMPONENT','RDFOWM';
commit;
end if;
exception
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: checking for WM usage: '||SQLERRM);
-- RAISE;
end;
-- VPD
begin
execute immediate
'select count(*) from mdsys.rdf_parameter
where namespace = :1 and attribute = :2'
into vpd_used
using 'COMPONENT','RDFVPD';
if (vpd_used > 0) then
-- set status to INVALID
execute immediate
'update mdsys.rdf_parameter
set description = :1
where namespace = :2 and attribute = :3'
using 'Feature not supported in current version',
'COMPONENT','RDFVPD';
commit;
end if;
exception
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: checking for VPD usage: '||SQLERRM);
-- RAISE;
end;
-- set sem_version in the rdf_paramter table --
-- see if we already have a row for sem_version --
begin
-- make sure rdf_parameter exists --
select count(*) into rdf_param_exists
from SYS.all_tables
where owner='MDSYS' and table_name='RDF_PARAMETER';
if (rdf_param_exists > 0) then
execute immediate
'select count(*)
from mdsys.rdf_parameter
where namespace = ''MDSYS'' and attribute = ''SEM_VERSION'''
into sem_version_exists;
-- check for invalid index status
begin
execute immediate
'select count(*)
from mdsys.rdf_parameter
where namespace = ''MDSYS'' and value = ''INVALID'' and
attribute IN (''PCSGM_INDEX_STATUS'')'
into invalid_idx;
exception
when table_not_found then NULL;
when others then
SYS.DBMS_SYSTEM.KSDWRT(SYS.DBMS_SYSTEM.TRACE_FILE,
'SEM_INSTALL: semvalidate: delete pre-existing PCSGM status rows: '||SQLERRM);
-- RAISE;
end;
-- Check if migration is needed
begin
execute immediate
'select count(*) from mdsys.rdf_parameter
where namespace = :1 and
attribute = :2 and
value = :3'
into need_mig
using 'MDSYS','RDF_VALUE$','INVALID_ORDER_COLUMNS';
end;
-- if there are any invalid objects or data then set description to invalid
-- otherwise it is valid
if ((num_invalid > 0) or (invalid_data > 0) or (invalid_idx > 0) or
(wm_used > 0) or (vpd_used > 0) or (need_mig > 0)) then
if (sem_version_exists > 0) then
execute immediate
'update mdsys.rdf_parameter
set value = ''18.1.0.0.0'', description = ''INVALID''
where namespace = ''MDSYS'' and attribute = ''SEM_VERSION''';
else
execute immediate
'insert into mdsys.rdf_parameter (namespace, attribute, value, description)
values (''MDSYS'', ''SEM_VERSION'', ''18.1.0.0.0'', ''INVALID'')';
end if;
else
if (sem_version_exists > 0) then
execute immediate
'update mdsys.rdf_parameter
set value = ''18.1.0.0.0'', description = ''VALID''
where namespace = ''MDSYS'' and attribute = ''SEM_VERSION''';
else
execute immediate
'insert into mdsys.rdf_parameter (namespace, attribute, value, description)
values (''MDSYS'', ''SEM_VERSION'', ''18.1.0.0.0'', ''VALID'')';
end if;
end if;
end if;
end;
commit;
end;
/
Rem ********************************************************************
Rem #16473696: Indicate Oracle-Supplied object
@?/rdbms/admin/sqlsessend.sql
Rem ********************************************************************
OHA YOOOO