Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 196657e

Browse files
committed
Updated plsql_optimizer_level according to PR comment.
Extracted sqlplus-specific code from ut_runner. Added generic code to ut_runner.
1 parent 9100923 commit 196657e

5 files changed

Lines changed: 199 additions & 170 deletions

File tree

source/core/types/ut_output_stream.tpb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ end;
2727
-- Oracle from changing the for loop to bulk collect into
2828
-- The row-by-row approach is needed to get the visible progress ot unit tests outputs
2929
-- as the tests get executed.
30-
alter type body ut_output_stream compile plsql_optimize_level = 1;
30+
alter type ut_output_stream compile body plsql_optimize_level = 1;

source/core/ut_runner.pkb

Lines changed: 29 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
create 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+
15292
end ut_runner;
15393
/

source/core/ut_runner.pks

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
create or replace package ut_runner authid definer 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+
10+
type tt_call_params is table of t_call_param;
11+
12+
type t_run_params is record(
13+
ut_paths varchar2(4000),
14+
call_params tt_call_params
15+
);
16+
317
procedure run(a_path in varchar2, a_reporter in ut_reporter);
418

519
-- implementation to be changed
@@ -8,17 +22,13 @@ create or replace package ut_runner authid definer is
822

923

1024
----------------------------
11-
-- SQLPlus executor helper procedures and functions.
12-
13-
--returns a text to be executed by sqlplus in order to make all the script call parameters optional
14-
--@param a_params_count - determines the number of parameters to be made optional (default is 100)
15-
function get_optional_params_script(a_params_count integer := 100) return ut_varchar2_list pipelined;
25+
-- Client-side executor helper procedures and functions.
1626

17-
procedure set_call_params(a_params ut_varchar2_list);
27+
procedure set_run_params(a_params ut_varchar2_list);
1828

19-
function get_run_in_background_script return ut_varchar2_list pipelined;
29+
function get_run_params return t_run_params;
2030

21-
function get_outputs_script return ut_varchar2_list pipelined;
31+
function get_streamed_output_type_name return varchar2;
2232

2333
end ut_runner;
2434
/

source/ut_run.sql

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)