-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinstall.sql
119 lines (99 loc) · 3.1 KB
/
install.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--Purpose: Install PLSQL_LEXER.
--How to run:
-- alter session set current_schema=&schema_name;
-- @install
--#1: Stop the script at first error, make the installation less noisy.
whenever sqlerror exit failure
whenever oserror exit failure
set feedback off
--#2: Installation banner
prompt
prompt ============================
prompt = PLSQL_LEXER Installation =
prompt ============================
prompt
--#3: Quit if program is already installed.
prompt Looking for existing installation...
--Look for type names, throw error if any are found.
declare
v_installed_types varchar2(4000);
begin
select listagg(type_name, ',') within group (order by type_name)
into v_installed_types
from all_types
where type_name in
(
'CLOB_TABLE', 'VARCHAR2_TABLE',
'TOKEN', 'TOKEN_TABLE', 'TOKEN_TABLE_TABLE',
--Parser objects not ready yet:
-- 'NODE', 'NODE_TABLE', 'NUMBER_TABLE',
'MISPLACED_HINTS_CODE_TYPE', 'MISPLACED_HINTS_CODE_TABLE',
'MISPLACED_HINTS_SCHEMA_TYPE', 'MISPLACED_HINTS_SCHEMA_TABLE'
)
and owner = sys_context('userenv', 'current_schema');
if v_installed_types is not null then
raise_application_error(-20000, 'Installation failed, the following '||
'types already exist. Either run @uninstall.sql or manually remove '||
'these types: '||v_installed_types);
end if;
end;
/
--#4: Install types.
prompt Installing types...
start types.sql
--#5: Install packages.
prompt Installing packages...
start packages/plsql_lexer.plsql
--Parser objects not ready yet:
--start packages/syntax_tree.plsql
--start packages/plsql_parser.spc
--start packages/plsql_parser.bdy
start packages/statement_classifier.plsql
start packages/statement_splitter.plsql
start packages/statement_feedback.plsql
start packages/statement_terminator.plsql
start packages/misplaced_hints.plsql
--#6: Verify installation and print success message.
prompt Verifying installation...
--Display all invalid objects.
column owner format a30;
column object_name format a30;
column object_type format a13;
select owner, object_name, object_type
from all_objects
where object_name in
(
'PLSQL_LEXER', 'STATEMENT_CLASSIFIER', 'STATEMENT_SPLITTER', 'STATEMENT_FEEDBACK', 'STATEMENT_TERMINATOR', 'MISPLACED_HINTS'
--Parser objects not ready yet:
--,'PLSQL_PARSER', 'SYNTAX_TREE'
)
and owner = sys_context('userenv', 'current_schema')
and status <> 'VALID';
--Raise error if any packages are invalid.
--(Because compilation errors may be "warnings" that won't fail the script.)
declare
v_count number;
begin
select count(*)
into v_count
from all_objects
where object_name in
(
'PLSQL_LEXER', 'STATEMENT_CLASSIFIER', 'STATEMENT_SPLITTER', 'STATEMENT_FEEDBACK', 'STATEMENT_TERMINATOR', 'MISPLACED_HINTS'
--Parser objects not ready yet:
--,'PLSQL_PARSER', 'SYNTAX_TREE'
)
and owner = sys_context('userenv', 'current_schema')
and status <> 'VALID';
if v_count >= 1 then
raise_application_error(-20000, 'Installation failed, the above objects '||
'are invalid.');
end if;
end;
/
prompt
prompt Installation successful.
--#7: Return SQL*Plus to normal environment.
whenever sqlerror continue
whenever oserror continue
set feedback on