@@ -70,63 +70,170 @@ set verify off
7070set heading off
7171
7272
73- -- -----------------------------------------------
74- -- Making SQLPlus parameters options
75- -- -----------------------------------------------
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+ */
7678set define off
77- spool make_input_params_optional .sql .tmp
79+ spool define_params_variable .sql .tmp
7880declare
7981 l_sql_columns varchar2 (4000 );
82+ l_params varchar2 (4000 );
8083begin
8184 for i in 1 .. 100 loop
8285 dbms_output .put_line (' column ' || i|| ' new_value ' || i);
8386 l_sql_columns := l_sql_columns || ' null as "' || i|| ' ",' ;
87+ l_params := l_params || ' ' ' ' ' &&' || i|| ' ' ' ' ' ,' ;
8488 end loop;
8589 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;' );
8691end;
8792/
8893spool off
8994set define &
9095
91- @@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
92100
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
93109
94- -- 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+ );
95116
96- -- -----------------------------------------------
97- -- Defining reporter objects
98- -- -----------------------------------------------
117+ type tt_call_params is table of t_call_param;
99118
119+ l_input_params ut_varchar2_list := ut_varchar2_list(&¶m_list);
120+ l_call_params tt_call_params;
100121
101- -- -----------------------------------------------
102- -- Preparing for execution (in background)
103- -- -----------------------------------------------
122+ l_run_cursor_sql varchar2 (32767 );
123+ l_out_cursor_sql varchar2 (32767 );
104124
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;
105195
106- set define off
107- spool set_run_params .sql .tmp
108- declare
109- l_params varchar2 (4000 );
110196begin
111- for i in 1 .. 100 loop
112- 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;
113214 end loop;
114- 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;
115225end;
116226/
117- spool off
118- set define &
119227
120- @@set_run_params .sql .tmp
121228
229+ /*
230+ * Generate runner script
231+ */
122232spool run_in_backgroung .sql .tmp
123233declare
124- l_run_params ut_runner .t_run_params := ut_runner .get_run_params ();
125- l_color_enabled varchar2 (5 ) := case when l_run_params .color_enabled then ' true' else ' false' end;
126- procedure p(a_text varchar2 ) is
127- begin
128- dbms_output .put_line (a_text);
129- 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;
130237begin
131238 p( ' set serveroutput on size unlimited format truncated' );
132239 p( ' set trimspool on' );
@@ -137,14 +244,17 @@ begin
137244 p( ' v_reporter ut_reporter_base;' );
138245 p( ' v_reporters_list ut_reporters := ut_reporters();' );
139246 p( ' begin' );
140- if l_run_params .call_params is not null then
141- for i in 1 .. l_run_params .call_params .count loop
142- p(' v_reporter := ' || l_run_params .call_params (i).ut_reporter_name|| ' ();' );
143- p(' v_reporter.reporter_id := ' ' ' || l_run_params .call_params (i).reporter_id|| ' ' ' ;' );
144- 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;' );
145254 end loop;
146255 end if;
147- 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|| ' );' );
148258 p( ' end;' );
149259 p( ' /' );
150260 p( ' spool off' );
@@ -153,48 +263,63 @@ end;
153263/
154264spool off
155265
266+ /*
267+ * Generate output retrieval script
268+ */
156269spool gather_data_from_outputs .sql .tmp
157270declare
158- 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 );
159274 l_need_spool boolean ;
160- procedure p(a_text varchar2 ) is
161- begin
162- dbms_output .put_line (a_text);
163- end;
275+ procedure p(a_text varchar2 ) is begin dbms_output .put_line (a_text); end;
164276begin
165- p(' declare l_date date := sysdate; begin loop exit when l_date < sysdate; end loop; end;' );
166- p(' /' );
167- if l_run_params .call_params is not null then
168- for i in 1 .. l_run_params .call_params .count loop
169- p(' set termout ' || l_run_params .call_params (i).output_to_screen);
170- l_need_spool := (l_run_params .call_params (i).output_file_name is not null );
171- p(case when l_need_spool then ' spool ' || l_run_params .call_params (i).output_file_name|| chr(10 ) end||
172- ' select * from table( ut_output_buffer.get_lines(' ' ' || l_run_params .call_params (i).reporter_id|| ' ' ' ) );' ||
173- 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;
174290 end loop;
175291 end if;
176292end;
177293/
178-
179294spool off
180- set termout off
295+
296+
297+ /*
298+ * Execute runner script in background process
299+ */
181300set define #
182301-- try running on windows
183302$ start sqlplus # #1 @run_in_backgroung.sql.tmp
184303-- try running on linus/unix
185304! sqlplus # #1 @run_in_backgroung.sql.tmp &
186305set define &
187306set termout on
307+
308+
188309-- make sure we fetch row by row to indicate the progress
189310set arraysize 1
311+ /*
312+ * Gather outputs from reporters one by one while runner script executes.
313+ */
190314@gather_data_from_outputs .sql .tmp
191315
192316set termout off
193- -- cleanup temporary sql files
317+ /*
318+ * cleanup temporary sql files
319+ */
194320-- try running on windows
195321$ del * .sql .tmp
196322-- try running on linus/unix
197323! rm * .sql .tmp
198- set termout on
199324
200325exit
0 commit comments