11create or replace package body ut_runner is
22
3- type t_call_param is record (
4- ut_reporter_name varchar2(4000),
5- output_file_name varchar2(4000),
6- output_to_screen varchar2(3) := 'off',
7- output_id varchar2(4000)
8- );
9- type tt_call_params is table of t_call_param;
10-
11- g_call_params tt_call_params;
12-
13- g_ut_paths varchar2(4000);
14-
15- function get_streamed_output_type return varchar2 is
16- l_result varchar2(255);
17- begin
18- select type_name
19- into l_result
20- from user_types where supertype_name = 'UT_OUTPUT_STREAM';
21- return lower(l_result)||'()';
22- end;
3+ g_run_params t_run_params;
234
245 procedure run(a_paths in ut_varchar2_list, a_reporter in ut_reporter) is
256 l_objects_to_run ut_objects_list;
@@ -47,27 +28,11 @@ create or replace package body ut_runner is
4728 run(ut_varchar2_list(coalesce(a_path, sys_context('userenv', 'current_schema'))), a_reporter);
4829 end run;
4930
50- function get_optional_params_script(a_params_count integer := 100) return ut_varchar2_list pipelined is
51- l_sql_columns varchar2(4000);
52- l_params varchar2(4000);
31+ procedure set_run_params(a_params ut_varchar2_list) is
32+ l_call_param t_call_param;
33+ l_call_params tt_call_params := tt_call_params();
34+ l_ut_paths varchar2(4000);
5335 begin
54- for i in 1 .. a_params_count loop
55- pipe row ('column '||i||' new_value '||i);
56- end loop;
57- for i in 1 .. a_params_count loop
58- l_sql_columns := l_sql_columns ||'null as "'||i||'",';
59- l_params := l_params || '''&&'||i||''',';
60- end loop;
61- pipe row ('select '||rtrim(l_sql_columns, ',') ||' from dual where rownum = 0;');
62- pipe row ('' );
63- pipe row ('exec ut_runner.set_call_params(ut_varchar2_list('||rtrim(l_params, ',')||'));' );
64- return;
65- end;
66-
67- procedure set_call_params(a_params ut_varchar2_list) is
68- l_call_param t_call_param;
69- begin
70- g_call_params := tt_call_params();
7136 for param in
7237 ( with
7338 param_vals as(
@@ -80,74 +45,49 @@ create or replace package body ut_runner is
8045 where param_type is not null)
8146 loop
8247 if param.param_type = 'f' then
83- g_call_params .extend;
84- g_call_params(g_call_params .last) := l_call_param;
85- g_call_params(g_call_params .last).ut_reporter_name := param.param_value;
86- elsif g_call_params .last is not null then
48+ l_call_params .extend;
49+ l_call_params(l_call_params .last) := l_call_param;
50+ l_call_params(l_call_params .last).ut_reporter_name := param.param_value;
51+ elsif l_call_params .last is not null then
8752 if param.param_type = 'o' then
88- g_call_params(g_call_params .last).output_file_name := param.param_value;
53+ l_call_params(l_call_params .last).output_file_name := param.param_value;
8954 elsif param.param_type = 's' then
90- g_call_params(g_call_params .last).output_to_screen := 'on';
55+ l_call_params(l_call_params .last).output_to_screen := 'on';
9156 end if;
9257 end if;
9358 end loop;
9459
9560 begin
9661 select ''''||replace(ut_paths,',',''',''')||''''
97- into g_ut_paths
62+ into g_run_params.ut_paths
9863 from (select regexp_substr(column_value,'-p\=(.*)',1,1,'c',1) as ut_paths from table(a_params) )
9964 where ut_paths is not null;
10065 exception
10166 when no_data_found then
102- g_ut_paths := 'user';
67+ g_run_params.ut_paths := 'user';
10368 when too_many_rows then
10469 raise_application_error(-20000, 'Parameter "-p=ut_paths" defined more than once. Only one "-p=ut_paths" parameter can be used.');
10570 end;
106-
107- end;
108-
109- function get_run_in_background_script return ut_varchar2_list pipelined is
110- l_output_id varchar2(128);
111- l_output_type varchar2(256);
112- begin
113-
114- l_output_type := get_streamed_output_type();
115- pipe row( 'set serveroutput on size unlimited format truncated');
116- pipe row( 'set pagesize 0');
117- pipe row( 'set linesize 4000');
118- pipe row( 'spool run_background.log');
119- pipe row( 'declare');
120- pipe row( ' v_reporter ut_reporter;');
121- pipe row( ' v_reporters_list ut_reporters_list := ut_reporters_list();');
122- pipe row( 'begin');
123- for i in 1 .. cardinality(g_call_params) loop
124- execute immediate 'begin :l_output_id := '||l_output_type||'.generate_output_id(); end;'
125- using out g_call_params(i).output_id;
126- pipe row(' v_reporter := '||g_call_params(i).ut_reporter_name||'('||l_output_type||');');
127- pipe row(' v_reporter.output.output_id := '''||g_call_params(i).output_id||''';');
128- pipe row(' v_reporters_list.extend; v_reporters_list(v_reporters_list.last) := v_reporter;');
71+ for i in 1 .. cardinality(l_call_params) loop
72+ execute immediate 'begin :l_output_id := '||get_streamed_output_type_name()||'().generate_output_id(); end;'
73+ using out l_call_params(i).output_id;
12974 end loop;
130- pipe row( ' ut.run( ut_varchar2_list('||g_ut_paths||'), ut_composite_reporter( v_reporters_list ) );');
131- pipe row( 'end;');
132- pipe row( '/');
133- pipe row( 'exit');
134-
135- return;
136- end;
75+ g_run_params.call_params := l_call_params;
76+ end set_run_params;
13777
138- function get_outputs_script return ut_varchar2_list pipelined is
78+ function get_run_params return t_run_params is
13979 begin
140- for i in 1 .. cardinality(g_call_params) loop
141- pipe row('set termout '||g_call_params(i).output_to_screen);
142- if g_call_params(i).output_file_name is not null then
143- pipe row('spool '||g_call_params(i).output_file_name);
144- pipe row('select * from table( '||get_streamed_output_type()||'.get_lines('''||g_call_params(i).output_id||''') );');
145- pipe row('spool off');
146- else
147- pipe row('select * from table( '||get_streamed_output_type()||'.get_lines('''||g_call_params(i).output_id||''') );');
148- end if;
149- end loop;
80+ return g_run_params;
15081 end;
15182
83+ function get_streamed_output_type_name return varchar2 is
84+ l_result varchar2(255);
85+ begin
86+ select type_name
87+ into l_result
88+ from user_types where supertype_name = 'UT_OUTPUT_STREAM';
89+ return lower(l_result);
90+ end;
91+
15292end ut_runner;
15393/
0 commit comments