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

Skip to content

Commit 45643e0

Browse files
committed
Tidy up code
1 parent a67b853 commit 45643e0

4 files changed

Lines changed: 82 additions & 54 deletions

File tree

source/core/ut_utils.pks

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ create or replace package ut_utils authid definer is
114114
gc_invalid_package constant pls_integer := -6550;
115115
pragma exception_init(ex_invalid_package, -6550);
116116

117+
ex_failure_for_all exception;
118+
gc_failure_for_all constant pls_integer := -24381;
119+
pragma exception_init (ex_failure_for_all, -24381);
120+
117121
gc_max_storage_varchar2_len constant integer := 4000;
118122
gc_max_output_string_length constant integer := 4000;
119123
gc_max_input_string_length constant integer := gc_max_output_string_length - 2; --we need to remove 2 chars for quotes around string

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 68 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ create or replace package body ut_compound_data_helper is
1717
*/
1818

1919
g_diff_count integer;
20-
20+
gc_xpath_extract_reg constant varchar2(50) := '^((/ROW/)|^(//)|^(/\*/))?(.*)';
2121
type t_type_name_map is table of varchar2(128) index by binary_integer;
2222
g_type_name_map t_type_name_map;
2323
g_anytype_name_map t_type_name_map;
@@ -46,8 +46,6 @@ create or replace package body ut_compound_data_helper is
4646

4747
function get_columns_diff_ordered(a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab)
4848
return tt_column_diffs is
49-
l_column_filter varchar2(32767);
50-
l_sql varchar2(32767);
5149
l_results tt_column_diffs;
5250
begin
5351
with
@@ -87,8 +85,6 @@ create or replace package body ut_compound_data_helper is
8785

8886
function get_columns_diff_unordered(a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab)
8987
return tt_column_diffs is
90-
l_column_filter varchar2(32767);
91-
l_sql varchar2(32767);
9288
l_results tt_column_diffs;
9389
begin
9490
with
@@ -125,11 +121,11 @@ create or replace package body ut_compound_data_helper is
125121
function get_columns_diff(a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab,a_order_enforced boolean := false)
126122
return tt_column_diffs is
127123
begin
128-
if a_order_enforced then
129-
return get_columns_diff_ordered(a_expected,a_actual);
130-
else
131-
return get_columns_diff_unordered(a_expected,a_actual);
132-
end if;
124+
return
125+
case
126+
when a_order_enforced then get_columns_diff_ordered(a_expected,a_actual)
127+
else get_columns_diff_unordered(a_expected,a_actual)
128+
end;
133129
end;
134130

135131
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return clob is
@@ -139,8 +135,10 @@ create or replace package body ut_compound_data_helper is
139135
return l_pk_value;
140136
end;
141137

142-
procedure generate_not_equal_stmt(a_data_info ut_cursor_column, a_pk_table ut_varchar2_list, a_not_equal_stmt in out nocopy clob,
143-
a_col_name varchar2) is
138+
procedure generate_not_equal_stmt(
139+
a_data_info ut_cursor_column, a_pk_table ut_varchar2_list,
140+
a_not_equal_stmt in out nocopy clob, a_col_name varchar2
141+
) is
144142
l_pk_tab ut_varchar2_list := coalesce(a_pk_table,ut_varchar2_list());
145143
l_index integer;
146144
l_sql_stmt varchar2(32767);
@@ -164,8 +162,10 @@ create or replace package body ut_compound_data_helper is
164162
end if;
165163
end;
166164

167-
procedure generate_join_by_stmt(a_data_info ut_cursor_column, a_pk_table ut_varchar2_list, a_join_by_stmt in out nocopy clob,
168-
a_col_name varchar2) is
165+
procedure generate_join_by_stmt(
166+
a_data_info ut_cursor_column, a_pk_table ut_varchar2_list,
167+
a_join_by_stmt in out nocopy clob, a_col_name varchar2
168+
) is
169169
l_pk_tab ut_varchar2_list := coalesce(a_pk_table,ut_varchar2_list());
170170
l_index integer;
171171
l_sql_stmt varchar2(32767);
@@ -192,9 +192,10 @@ create or replace package body ut_compound_data_helper is
192192
ut_utils.append_to_clob(a_equal_stmt,l_sql_stmt);
193193
end;
194194

195-
procedure generate_partition_stmt(a_data_info ut_cursor_column, a_partition_stmt in out nocopy clob,
196-
a_pk_table in ut_varchar2_list,a_col_name in varchar2,a_alias varchar2 := 'ucd.') is
197-
195+
procedure generate_partition_stmt(
196+
a_data_info ut_cursor_column, a_partition_stmt in out nocopy clob,
197+
a_pk_table in ut_varchar2_list,a_col_name in varchar2,a_alias varchar2 := 'ucd.'
198+
) is
198199
l_alias varchar2(10) := a_alias;
199200
l_pk_tab ut_varchar2_list := coalesce(a_pk_table,ut_varchar2_list());
200201
l_index integer;
@@ -284,16 +285,18 @@ create or replace package body ut_compound_data_helper is
284285
generate_not_equal_stmt(l_cursor_info(i),a_pk_table,a_not_equal_stmt,l_col_name);
285286
end if;
286287
end loop;
287-
--Finish parition by
288+
--Finish partition by
288289
ut_utils.append_to_clob(a_partition_stmt,l_partition_tmp||' order by '||l_partition_tmp||' ) dup_no ');
289290
else
290291
--Partition by piece when no data
291292
ut_utils.append_to_clob(a_partition_stmt,', 1 dup_no ');
292293
end if;
293294
end;
294295

295-
procedure get_act_and_exp_set(a_current_stmt in out nocopy clob, a_partition_stmt clob, a_select_stmt clob,
296-
a_xmltable_stmt clob, a_unordered boolean,a_type varchar2) is
296+
procedure get_act_and_exp_set(
297+
a_current_stmt in out nocopy clob, a_partition_stmt clob, a_select_stmt clob,
298+
a_xmltable_stmt clob, a_unordered boolean,a_type varchar2
299+
) is
297300
l_temp_string varchar2(32767);
298301
l_ut_owner varchar2(250) := ut_utils.ut_owner;
299302
begin
@@ -409,7 +412,8 @@ create or replace package body ut_compound_data_helper is
409412
return l_column_list;
410413
end;
411414

412-
function get_rows_diff_by_sql(a_act_cursor_info ut_cursor_column_tab,a_exp_cursor_info ut_cursor_column_tab,
415+
function get_rows_diff_by_sql(
416+
a_act_cursor_info ut_cursor_column_tab,a_exp_cursor_info ut_cursor_column_tab,
413417
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
414418
a_join_by_list ut_varchar2_list, a_unordered boolean, a_enforce_column_order boolean := false
415419
) return tt_row_diffs is
@@ -601,14 +605,17 @@ create or replace package body ut_compound_data_helper is
601605

602606
procedure insert_diffs_result(a_diff_tab t_diff_tab, a_diff_id raw) is
603607
begin
604-
forall idx in 1..a_diff_tab.count
608+
forall idx in 1..a_diff_tab.count save exceptions
605609
insert into ut_compound_data_diff_tmp
606610
( diff_id, act_item_data, act_data_id, exp_item_data, exp_data_id, item_no, duplicate_no )
607611
values
608612
(a_diff_id,
609613
xmlelement( name "ROW", a_diff_tab(idx).act_item_data), a_diff_tab(idx).act_data_id,
610614
xmlelement( name "ROW", a_diff_tab(idx).exp_item_data), a_diff_tab(idx).exp_data_id,
611615
a_diff_tab(idx).item_no, a_diff_tab(idx).dup_no);
616+
exception
617+
when ut_utils.ex_failure_for_all then
618+
raise_application_error(ut_utils.gc_failure_for_all,'Failure to insert a diff tmp data.');
612619
end;
613620

614621
procedure set_rows_diff(a_rows_diff integer) is
@@ -651,7 +658,8 @@ create or replace package body ut_compound_data_helper is
651658
return l_result;
652659
end;
653660

654-
function get_missing_filter_columns(a_cursor_info ut_cursor_column_tab, a_column_filter_list ut_varchar2_list) return ut_varchar2_list is
661+
function get_missing_filter_columns(a_cursor_info ut_cursor_column_tab, a_column_filter_list ut_varchar2_list)
662+
return ut_varchar2_list is
655663
l_result ut_varchar2_list := ut_varchar2_list();
656664
begin
657665
select fl.column_value
@@ -689,20 +697,20 @@ create or replace package body ut_compound_data_helper is
689697
if a_include_xpath.count > 0 and a_exclude_xpath.count > 0 then
690698
select col_names bulk collect into l_filtered_set
691699
from(
692-
select regexp_replace(column_value,'^((/ROW/)|^(//)|^(/\*/))?(.*)','\5') col_names
700+
select regexp_replace(column_value,gc_xpath_extract_reg,'\5') col_names
693701
from table(a_include_xpath)
694702
minus
695-
select regexp_replace(column_value,'^((/ROW/)|^(//)|^(/\*/))?(.*)','\5') col_names
703+
select regexp_replace(column_value,gc_xpath_extract_reg,'\5') col_names
696704
from table(a_exclude_xpath)
697705
);
698706
l_include := true;
699707
elsif a_include_xpath.count > 0 and a_exclude_xpath.count = 0 then
700-
select regexp_replace(column_value,'^((/ROW/)|^(//)|^(/\*/))?(.*)','\5') col_names
708+
select regexp_replace(column_value,gc_xpath_extract_reg,'\5') col_names
701709
bulk collect into l_filtered_set
702710
from table(a_include_xpath);
703711
l_include := true;
704712
elsif a_include_xpath.count = 0 and a_exclude_xpath.count > 0 then
705-
select regexp_replace(column_value,'^((/ROW/)|^(//)|^(/\*/))?(.*)','\5') col_names
713+
select regexp_replace(column_value,gc_xpath_extract_reg,'\5') col_names
706714
bulk collect into l_filtered_set
707715
from table(a_exclude_xpath);
708716
l_include := false;
@@ -719,15 +727,17 @@ create or replace package body ut_compound_data_helper is
719727
return l_result;
720728
end;
721729

722-
function contains_collection (a_cursor_info ut_cursor_column_tab) return number is
730+
function contains_collection (a_cursor_info ut_cursor_column_tab)
731+
return number is
723732
l_collection_elements number;
724733
begin
725734
select count(1) into l_collection_elements from
726735
table(a_cursor_info) c where c.is_collection = 1;
727736
return l_collection_elements;
728737
end;
729738

730-
function remove_incomparable_cols( a_cursor_details ut_cursor_column_tab,a_incomparable_cols ut_varchar2_list) return ut_cursor_column_tab is
739+
function remove_incomparable_cols( a_cursor_details ut_cursor_column_tab,a_incomparable_cols ut_varchar2_list)
740+
return ut_cursor_column_tab is
731741
l_result ut_cursor_column_tab;
732742
begin
733743
select ut_cursor_column(i.parent_name,i.access_path,i.has_nested_col,i.transformed_name,i.hierarchy_level,i.column_position ,
@@ -742,41 +752,49 @@ create or replace package body ut_compound_data_helper is
742752
end;
743753

744754
function getxmlchildren(a_parent_name varchar2,a_cursor_table ut_cursor_column_tab)
745-
return xmltype is
746-
l_result xmltype;
747-
begin
748-
select xmlagg(xmlelement(evalname t.column_name,t.column_type,
749-
getxmlchildren(t.column_name,a_cursor_table)))
750-
into l_result
751-
from table(a_cursor_table) t
752-
where (a_parent_name is not null and parent_name = a_parent_name and hierarchy_level > 1 and column_name is not null)
753-
or (a_parent_name is null and parent_name is null and hierarchy_level = 1 and column_name is not null)
754-
having count(*) > 0;
755-
755+
return xmltype is
756+
l_result xmltype;
757+
begin
758+
select xmlagg(xmlelement(evalname t.column_name,t.column_type,
759+
getxmlchildren(t.column_name,a_cursor_table)))
760+
into l_result
761+
from table(a_cursor_table) t
762+
where (a_parent_name is not null and parent_name = a_parent_name and hierarchy_level > 1 and column_name is not null)
763+
or (a_parent_name is null and parent_name is null and hierarchy_level = 1 and column_name is not null)
764+
having count(*) > 0;
756765

757-
return l_result;
758-
end;
766+
return l_result;
767+
end;
759768

760-
function is_sql_compare_allowed(a_type_name varchar2) return boolean is
769+
function is_sql_compare_allowed(a_type_name varchar2)
770+
return boolean is
771+
l_assert boolean;
761772
begin
762773
--clob/blob/xmltype/object/nestedcursor/nestedtable
763774
if a_type_name IN (g_type_name_map(dbms_sql.blob_type),
764775
g_type_name_map(dbms_sql.clob_type),
765776
g_type_name_map(dbms_sql.bfile_type),
766777
g_anytype_name_map(dbms_types.typecode_namedcollection))
767778
then
768-
return false;
779+
l_assert := false;
769780
else
770-
return true;
781+
l_assert := true;
771782
end if;
783+
return l_assert;
772784
end;
773785

774-
function get_column_type_desc(a_type_code in integer, a_dbms_sql_desc in boolean) return varchar2 is
786+
function get_column_type_desc(a_type_code in integer, a_dbms_sql_desc in boolean)
787+
return varchar2 is
775788
begin
776-
return case when a_dbms_sql_desc then g_type_name_map(a_type_code) else g_anytype_name_map(a_type_code) end;
789+
return
790+
case
791+
when a_dbms_sql_desc then g_type_name_map(a_type_code)
792+
else g_anytype_name_map(a_type_code)
793+
end;
777794
end;
778795

779-
function get_anytype_members_info( a_anytype anytype ) return t_anytype_members_rec is
796+
function get_anytype_members_info( a_anytype anytype )
797+
return t_anytype_members_rec is
780798
l_result t_anytype_members_rec;
781799
begin
782800
if a_anytype is not null then
@@ -795,7 +813,8 @@ create or replace package body ut_compound_data_helper is
795813
return l_result;
796814
end;
797815

798-
function get_attr_elem_info( a_anytype anytype, a_pos pls_integer := null ) return t_anytype_elem_info_rec is
816+
function get_attr_elem_info( a_anytype anytype, a_pos pls_integer := null )
817+
return t_anytype_elem_info_rec is
799818
l_result t_anytype_elem_info_rec;
800819
begin
801820
if a_anytype is not null then

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ create or replace package ut_compound_data_helper authid definer is
9999
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
100100
) return tt_row_diffs;
101101

102-
function get_rows_diff_by_sql(a_act_cursor_info ut_cursor_column_tab,a_exp_cursor_info ut_cursor_column_tab,
102+
function get_rows_diff_by_sql(
103+
a_act_cursor_info ut_cursor_column_tab,a_exp_cursor_info ut_cursor_column_tab,
103104
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
104105
a_join_by_list ut_varchar2_list, a_unordered boolean, a_enforce_column_order boolean := false
105106
) return tt_row_diffs;

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ create or replace type body ut_data_value_refcursor as
1616
limitations under the License.
1717
*/
1818

19-
constructor function ut_data_value_refcursor(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor) return self as result is
19+
constructor function ut_data_value_refcursor(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor)
20+
return self as result is
2021
begin
2122
init(a_value);
2223
return;
@@ -122,7 +123,9 @@ create or replace type body ut_data_value_refcursor as
122123
return l_result_string;
123124
end;
124125

125-
member function diff( a_other ut_data_value, a_unordered boolean := false, a_join_by_list ut_varchar2_list:=ut_varchar2_list() ) return varchar2 is
126+
member function diff(
127+
a_other ut_data_value, a_unordered boolean := false, a_join_by_list ut_varchar2_list:=ut_varchar2_list()
128+
) return varchar2 is
126129
l_result clob;
127130
l_results ut_utils.t_clob_tab := ut_utils.t_clob_tab();
128131
l_result_string varchar2(32767);
@@ -170,7 +173,9 @@ create or replace type body ut_data_value_refcursor as
170173
return l_message;
171174
end;
172175

173-
function remove_incomparable_cols( a_cursor_details ut_cursor_column_tab,a_column_diffs ut_compound_data_helper.tt_column_diffs) return ut_cursor_column_tab is
176+
function remove_incomparable_cols(
177+
a_cursor_details ut_cursor_column_tab,a_column_diffs ut_compound_data_helper.tt_column_diffs
178+
) return ut_cursor_column_tab is
174179
l_incomparable_cols ut_varchar2_list := ut_varchar2_list();
175180
l_filter_out ut_cursor_column_tab;
176181
begin
@@ -186,7 +191,6 @@ create or replace type body ut_data_value_refcursor as
186191

187192
function get_diff_message (a_row_diff ut_compound_data_helper.t_row_diffs,a_is_unordered boolean) return varchar2 is
188193
begin
189-
190194
if a_is_unordered then
191195
if a_row_diff.pk_value is not null then
192196
return ' PK '||a_row_diff.pk_value||' - '||rpad(a_row_diff.diff_type,10)||a_row_diff.diffed_row;

0 commit comments

Comments
 (0)