@@ -69,51 +69,171 @@ set longchunksize 30000
6969set verify off
7070set heading off
7171
72+
73+
74+ column param_list new_value param_list noprint;
75+ /*
76+ * Prepare script to make SQLPlus parameters optional and pass parameters call to param_list variable
77+ */
7278set define off
73- spool make_input_params_optional .sql .tmp
79+ spool define_params_variable .sql .tmp
7480declare
7581 l_sql_columns varchar2 (4000 );
82+ l_params varchar2 (4000 );
7683begin
7784 for i in 1 .. 100 loop
7885 dbms_output .put_line (' column ' || i|| ' new_value ' || i);
7986 l_sql_columns := l_sql_columns || ' null as "' || i|| ' ",' ;
87+ l_params := l_params || ' ' ' ' ' &&' || i|| ' ' ' ' ' ,' ;
8088 end loop;
8189 dbms_output .put_line (' select ' || rtrim(l_sql_columns, ' ,' ) || ' from dual where rownum = 0;' );
90+ dbms_output .put_line (' select ' ' ' || rtrim(l_params, ' ,' )|| ' ' ' as param_list from dual;' );
8291end;
8392/
8493spool off
8594set define &
8695
87- @@make_input_params_optional .sql .tmp
96+ /*
97+ * Make SQLPlus parameters optional and pass parameters call to param_list variable
98+ */
99+ @@define_params_variable .sql .tmp
88100
101+ var l_paths varchar2 (4000 );
102+ var l_color_enabled varchar2 (5 );
103+ var l_run_params_cur refcursor;
104+ var l_out_params_cur refcursor;
105+ /*
106+ * Parse parameters and returning as variables
107+ */
108+ declare
89109
90- -- prepare executor scripts
110+ type t_call_param is record (
111+ ut_reporter_name varchar2 (4000 ) := ' ut_documentation_reporter' ,
112+ output_file_name varchar2 (4000 ),
113+ output_to_screen varchar2 (3 ) := ' on' ,
114+ reporter_id varchar2 (250 )
115+ );
116+
117+ type tt_call_params is table of t_call_param;
118+
119+ l_input_params ut_varchar2_list := ut_varchar2_list(&¶m_list);
120+ l_call_params tt_call_params;
121+
122+ l_run_cursor_sql varchar2 (32767 );
123+ l_out_cursor_sql varchar2 (32767 );
124+
125+ function parse_reporting_params(a_params ut_varchar2_list) return tt_call_params is
126+ l_default_call_param t_call_param;
127+ l_call_params tt_call_params := tt_call_params();
128+ l_force_out_to_screen boolean ;
129+ begin
130+ for param in (
131+ with
132+ param_vals as (
133+ select regexp_substr(column_value,' -([fos])\= ?(.*)' ,1 ,1 ,' c' ,1 ) param_type,
134+ regexp_substr(column_value,' -([fos])\= (.*)' ,1 ,1 ,' c' ,2 ) param_value
135+ from table(a_params)
136+ where column_value is not null )
137+ select param_type, param_value
138+ from param_vals
139+ where param_type is not null
140+ ) loop
141+ if param .param_type = ' f' or l_call_params .last is null then
142+ l_call_params .extend ;
143+ l_call_params(l_call_params .last ) := l_default_call_param;
144+ if param .param_type = ' f' then
145+ l_call_params(l_call_params .last ).ut_reporter_name := dbms_assert .simple_sql_name (param .param_value );
146+ end if;
147+ l_force_out_to_screen := false;
148+ end if;
149+ if param .param_type = ' o' then
150+ l_call_params(l_call_params .last ).output_file_name := param .param_value ;
151+ if not l_force_out_to_screen then
152+ l_call_params(l_call_params .last ).output_to_screen := ' off' ;
153+ end if;
154+ elsif param .param_type = ' s' then
155+ l_call_params(l_call_params .last ).output_to_screen := ' on' ;
156+ l_force_out_to_screen := true;
157+ end if;
158+ end loop;
159+ if l_call_params .count = 0 then
160+ l_call_params .extend ;
161+ l_call_params(1 ) := l_default_call_param;
162+ end if;
163+ for i in 1 .. cardinality(l_call_params) loop
164+ l_call_params(i).reporter_id := sys_guid();
165+ end loop;
166+ return l_call_params;
167+ end;
168+
169+ function parse_paths_param(a_params ut_varchar2_list) return varchar2 is
170+ l_paths varchar2 (4000 );
171+ begin
172+ begin
173+ select ' ' ' ' || replace(ut_paths,' ,' ,' ' ' ,' ' ' )|| ' ' ' '
174+ into l_paths
175+ from (select regexp_substr(column_value,' -p\= (.*)' ,1 ,1 ,' c' ,1 ) as ut_paths from table(a_params) )
176+ where ut_paths is not null ;
177+ exception
178+ when no_data_found then
179+ l_paths := ' user' ;
180+ when too_many_rows then
181+ raise_application_error(- 20000 , ' Parameter "-p=ut_path(s)" defined more than once. Only one "-p=ut_path(s)" parameter can be used.' );
182+ end;
183+ return l_paths;
184+ end;
185+
186+ function parse_color_enabled(a_params ut_varchar2_list) return varchar2 is
187+ begin
188+ for i in 1 .. cardinality(a_params) loop
189+ if a_params(i) = ' -c' then
190+ return ' true' ;
191+ end if;
192+ end loop;
193+ return ' false' ;
194+ end;
91195
92- set define off
93- spool set_run_params .sql .tmp
94- declare
95- l_params varchar2 (4000 );
96196begin
97- for i in 1 .. 100 loop
98- l_params := l_params || ' ' ' &&' || i|| ' ' ' ,' ;
197+ l_call_params := parse_reporting_params(l_input_params);
198+ for i in l_call_params .first .. l_call_params .last loop
199+ l_run_cursor_sql :=
200+ l_run_cursor_sql ||
201+ ' select ' ' ' || l_call_params(i).reporter_id|| ' ' ' as reporter_id,' ||
202+ ' ' ' ' || l_call_params(i).ut_reporter_name|| ' ' ' as reporter_name' ||
203+ ' from dual' ;
204+ l_out_cursor_sql :=
205+ l_out_cursor_sql ||
206+ ' select ' ' ' || l_call_params(i).reporter_id|| ' ' ' as reporter_id,' ||
207+ ' ' ' ' || l_call_params(i).output_to_screen|| ' ' ' as output_to_screen,' ||
208+ ' ' ' ' || l_call_params(i).output_file_name|| ' ' ' as output_file_name' ||
209+ ' from dual' ;
210+ if i < l_call_params .last then
211+ l_run_cursor_sql := l_run_cursor_sql || ' union all ' ;
212+ l_out_cursor_sql := l_out_cursor_sql || ' union all ' ;
213+ end if;
99214 end loop;
100- dbms_output .put_line (' exec ut_runner.set_run_params(ut_varchar2_list(' || rtrim(l_params, ' ,' )|| ' ));' );
215+
216+ :l_paths := parse_paths_param(l_input_params);
217+ :l_color_enabled := parse_color_enabled(l_input_params);
218+
219+ if l_run_cursor_sql is not null then
220+ open :l_run_params_cur for l_run_cursor_sql;
221+ end if;
222+ if l_out_cursor_sql is not null then
223+ open :l_out_params_cur for l_out_cursor_sql;
224+ end if;
101225end;
102226/
103- spool off
104- set define &
105227
106- @@set_run_params .sql .tmp
107228
229+ /*
230+ * Generate runner script
231+ */
108232spool run_in_backgroung .sql .tmp
109233declare
110- l_output_type varchar2 (256 ) := ut_runner .get_streamed_output_type_name ();
111- l_run_params ut_runner .t_run_params := ut_runner .get_run_params ();
112- l_color_enabled varchar2 (5 ) := case when l_run_params .color_enabled then ' true' else ' false' end;
113- procedure p(a_text varchar2 ) is
114- begin
115- dbms_output .put_line (a_text);
116- end;
234+ l_reporter_id varchar2 (250 );
235+ l_reporter_name varchar2 (250 );
236+ procedure p(a_text varchar2 ) is begin dbms_output .put_line (a_text); end;
117237begin
118238 p( ' set serveroutput on size unlimited format truncated' );
119239 p( ' set trimspool on' );
@@ -124,14 +244,17 @@ begin
124244 p( ' v_reporter ut_reporter_base;' );
125245 p( ' v_reporters_list ut_reporters := ut_reporters();' );
126246 p( ' begin' );
127- if l_run_params .call_params is not null then
128- for i in 1 .. l_run_params .call_params .count loop
129- p(' v_reporter := ' || l_run_params .call_params (i).ut_reporter_name|| ' (' || l_output_type|| ' ());' );
130- p(' v_reporter.output.output_id := ' ' ' || l_run_params .call_params (i).output_id|| ' ' ' ;' );
131- p(' v_reporters_list.extend; v_reporters_list(v_reporters_list.last) := v_reporter;' );
247+ if :l_run_params_cur%isopen then
248+ loop
249+ fetch :l_run_params_cur into l_reporter_id, l_reporter_name;
250+ exit when :l_run_params_cur%notfound;
251+ p(' v_reporter := ' || l_reporter_name|| ' ();' );
252+ p(' v_reporter.reporter_id := ' ' ' || l_reporter_id|| ' ' ' ;' );
253+ p(' v_reporters_list.extend; v_reporters_list(v_reporters_list.last) := v_reporter;' );
132254 end loop;
133255 end if;
134- p( ' ut_runner.run( ut_varchar2_list(' || l_run_params .ut_paths || ' ), v_reporters_list, a_color_console => ' || l_color_enabled|| ' );' );
256+ close :l_run_params_cur;
257+ p( ' ut_runner.run( ut_varchar2_list(' || :l_paths|| ' ), v_reporters_list, a_color_console => ' || :l_color_enabled|| ' );' );
135258 p( ' end;' );
136259 p( ' /' );
137260 p( ' spool off' );
@@ -140,49 +263,63 @@ end;
140263/
141264spool off
142265
266+ /*
267+ * Generate output retrieval script
268+ */
143269spool gather_data_from_outputs .sql .tmp
144270declare
145- l_output_type varchar2 (256 ) := ut_runner .get_streamed_output_type_name ();
146- l_run_params ut_runner .t_run_params := ut_runner .get_run_params ();
271+ l_reporter_id varchar2 (250 );
272+ l_output_file_name varchar2 (250 );
273+ l_output_to_screen varchar2 (250 );
147274 l_need_spool boolean ;
148- procedure p(a_text varchar2 ) is
149- begin
150- dbms_output .put_line (a_text);
151- end;
275+ procedure p(a_text varchar2 ) is begin dbms_output .put_line (a_text); end;
152276begin
153- p(' declare l_date date := sysdate; begin loop exit when l_date < sysdate; end loop; end;' );
154- p(' /' );
155- if l_run_params .call_params is not null then
156- for i in 1 .. l_run_params .call_params .count loop
157- p(' set termout ' || l_run_params .call_params (i).output_to_screen);
158- l_need_spool := (l_run_params .call_params (i).output_file_name is not null );
159- p(case when l_need_spool then ' spool ' || l_run_params .call_params (i).output_file_name|| chr(10 ) end||
160- ' select * from table( ' || l_output_type|| ' ().get_lines(' ' ' || l_run_params .call_params (i).output_id|| ' ' ' ) );' ||
161- case when l_need_spool then chr(10 )|| ' spool off' end);
277+ if :l_out_params_cur%isopen then
278+ loop
279+ fetch :l_out_params_cur into l_reporter_id, l_output_to_screen, l_output_file_name;
280+ exit when :l_out_params_cur%notfound;
281+ l_need_spool := (l_output_file_name is not null );
282+ p( ' set termout ' || l_output_to_screen);
283+ if l_need_spool then
284+ p( ' spool ' || l_output_file_name);
285+ end if;
286+ p( ' select * from table( ut_output_buffer.get_lines(' ' ' || l_reporter_id|| ' ' ' ) );' );
287+ if l_need_spool then
288+ p(' spool off' );
289+ end if;
162290 end loop;
163291 end if;
164292end;
165293/
166-
167294spool off
168- set termout off
295+
296+
297+ /*
298+ * Execute runner script in background process
299+ */
169300set define #
170301-- try running on windows
171302$ start sqlplus # #1 @run_in_backgroung.sql.tmp
172303-- try running on linus/unix
173304! sqlplus # #1 @run_in_backgroung.sql.tmp &
174305set define &
175306set termout on
307+
308+
176309-- make sure we fetch row by row to indicate the progress
177310set arraysize 1
311+ /*
312+ * Gather outputs from reporters one by one while runner script executes.
313+ */
178314@gather_data_from_outputs .sql .tmp
179315
180316set termout off
181- -- cleanup temporary sql files
317+ /*
318+ * cleanup temporary sql files
319+ */
182320-- try running on windows
183321$ del * .sql .tmp
184322-- try running on linus/unix
185323! rm * .sql .tmp
186- set termout on
187324
188325exit
0 commit comments