DBA Data[Home] [Help]

PACKAGE BODY: ORACLE_OCM.MGMT_CONFIG_UTL

Source


1 PACKAGE body            MGMT_CONFIG_UTL AS
2 
3 PLATFORM_WINDOWS32    CONSTANT BINARY_INTEGER := 7;
4 PLATFORM_WINDOWS64    CONSTANT BINARY_INTEGER := 8;
5 PLATFORM_OPENVMS      CONSTANT BINARY_INTEGER := 15;
6 
7 
8 -- ###############################################
9 -- The two local functions ENQUOTE_INTERNAL and
10 -- ENQUOTE_LITERAL below are copied from
11 -- rdbms/src/server/dict/sqlddl/prvtasrt.sql
12 -- label RDBMS_10.2.0.5.0_LINUX_100201
13 -- as a local implementation.
14 -- ###############################################
15 
16   --
17   -- Enquote a string using a given quote character
18   --
19   function ENQUOTE_INTERNAL(Str varchar2, Quote varchar2)
20            return varchar2 is
21     already_quoted boolean := substr(Str, 1, 1) = Quote;
22     len            binary_integer := length(Str);
23     pos            binary_integer;
24   begin
25     -- debug
26     -- dbms_output.put_line('Str: ' || Str);
27     -- dbms_output.put_line('Quote: ' || Quote);
28 
29     if (already_quoted) then
30       pos := 2;
31       -- if the last character of this string which is supposedly already
32       -- quoted is NOT the quote character, the string is clearly not
33       -- quoted. Raise value error
34       if (substr(Str, len, 1) <> Quote) then
35         raise value_error;
36       end if;
37       -- we change the number of characters we need to examine to one
38       -- less since we should not need to examine the last character.
39       -- See the comment on raising an error when
40       -- pos = len and already_quoted
41       len := len - 1;
42     else
43       pos := 1;
44     end if;
45     while (pos <= len) loop
46       -- debug
47       --  dbms_output.put_line('pos: ' || pos || ' len: ' || len ||
48       --                       ' Char: ' || substr(Str, pos, 1));
49       if (substr(Str, pos, 1) = Quote) then
50         -- if the current character is a quote then we have
51         --   to check a couple of things
52 
53         if ((pos < len) AND (substr(Str, pos + 1, 1) = Quote)) then
54           pos := pos + 1;
55         else
56           raise value_error;
57         end if;
58       end if;
59       pos := pos + 1;
60     end loop;
61     if (already_quoted) then
62       return Str;
63     else
64       return Quote || Str || Quote;
65     end if;
66   end ENQUOTE_INTERNAL;
67 
68 
69   --
70   -- ENQUOTE_LITERAL
71   --
72   -- Enquote a string literal.  Add leading and trailing single quotes
73   -- to a string literal.  Verify that all single quotes except leading
74   -- and trailing characters are paired with adjacent single quotes.
75   --
76   function ENQUOTE_LITERAL(Str varchar2)
77            return varchar2 is
78   begin
79     return ENQUOTE_INTERNAL(Str, '''');
80   end ENQUOTE_LITERAL;
81 
82 /*
83    Dummy funtion for fix Bug 12380852
84 */
85 FUNCTION no_opp(l_ocm_dir_path IN  VARCHAR) RETURN VARCHAR IS
86 BEGIN
87    return l_ocm_dir_path;
88 END no_opp;
89 
90 /*
91 Create or replace the directory object to recreate the path based on
92 new ORACLE_HOME.
93 Note:
94   1. This procedure is executed with invoker's rights. This is needed so that
95      ORACLE_OCM user does not need to be granted "execute" permission on "dbms_system" package.
96      Only SYS would be able to run this procedure without error as it has the privilege to execute "dbms_system" and re-create
97      the directory object ORACLE_OCM_CONFIG_DIR owned by it.
98   2. This procedure is only supported on release 10g onwards.
99      DBMS_SYSTEM.GET_ENV is supported 10g onwards.
100      DBMS_ASSERT.ENQUOTE_LITERAL is used if the DB version is 10gR2 onwards.
101 */
102 procedure create_replace_dir_obj IS
103     -- local variables
104   pfid            NUMBER;
105   root            VARCHAR2(2000);
106   hname           VARCHAR2(2000);
107   l_ocm_dir_path  VARCHAR2(4000);
108   l_ocm_dir_path2 VARCHAR2(4000);
109   l_dirsep        VARCHAR2(2);
110   l_vers          v$instance.version%TYPE;
111 BEGIN
112     -- get the platform id
113     SELECT platform_id INTO pfid FROM v$database;
114 
115     IF pfid = PLATFORM_OPENVMS THEN
116       -- ORA_ROOT is a VMS logical name
117       l_ocm_dir_path  := 'ORA_ROOT:[ccr.state]';
118       l_ocm_dir_path2 := 'ORA_ROOT:[ccr.state]';
119     ELSE
120       -- Get ORACLE_HOME
121       execute immediate 'BEGIN DBMS_SYSTEM.GET_ENV(''ORACLE_HOME'', :1); END;' using out root;
122       -- Get HOSTNAME
123       execute immediate 'BEGIN DBMS_SYSTEM.GET_ENV(''HOSTNAME'', :1); END;' using out hname;
124       -- Return platform-specific string
125       IF pfid = PLATFORM_WINDOWS32 OR pfid = PLATFORM_WINDOWS64
126       THEN
127         l_dirsep := '\'; --'
128       ELSE
129         l_dirsep := '/';
130       END IF;
131 
132       IF HNAME IS NULL THEN
133          l_ocm_dir_path := root || l_dirsep|| 'ccr' || l_dirsep || 'state';
134       ELSE
135          l_ocm_dir_path := root || l_dirsep|| 'ccr' || l_dirsep || 'hosts' || l_dirsep || hname || l_dirsep || 'state';
136       END IF;
137       l_ocm_dir_path2:= root || l_dirsep|| 'ccr' || l_dirsep || 'state';
138 
139     END IF;
140     select LPAD(version,10,'0') into l_vers from v$instance;
141     IF l_vers < '10.2.0.0.0' THEN
142         l_ocm_dir_path := ENQUOTE_LITERAL(l_ocm_dir_path);
143         l_ocm_dir_path2 := ENQUOTE_LITERAL(l_ocm_dir_path2);
144     ELSE
145         execute immediate 'SELECT DBMS_ASSERT.ENQUOTE_LITERAL(:1) FROM DUAL' into l_ocm_dir_path using l_ocm_dir_path;
146         execute immediate 'SELECT DBMS_ASSERT.ENQUOTE_LITERAL(:1) FROM DUAL' into l_ocm_dir_path2 using l_ocm_dir_path2;
147     END IF;
148     execute immediate 'CREATE OR REPLACE DIRECTORY ORACLE_OCM_CONFIG_DIR AS ' || no_opp(l_ocm_dir_path);
149     execute immediate 'CREATE OR REPLACE DIRECTORY ORACLE_OCM_CONFIG_DIR2 AS ' || no_opp(l_ocm_dir_path2);
150     COMMIT;
151 END create_replace_dir_obj;
152 
153 END MGMT_CONFIG_UTL;