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

Skip to content

Commit 004b537

Browse files
committed
Refactoring recursive calls for resolving complex types in cursor.
Changed `is_collection` and moved to `ut_cursor_column` Changed `get_anytype_members_info`, `get_attr_elem_info` and moved to `ut_compound_data_helper` Fixes to formatting.
1 parent ca9f8eb commit 004b537

7 files changed

Lines changed: 316 additions & 268 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ create or replace package body ut_compound_data_helper is
1616
limitations under the License.
1717
*/
1818

19-
g_user_defined_type pls_integer := dbms_sql.user_defined_type;
2019
g_diff_count integer;
21-
g_filter_tab ut_varchar2_list;
22-
20+
2321
type t_type_name_map is table of varchar2(128) index by binary_integer;
2422
g_type_name_map t_type_name_map;
2523
g_anytype_name_map t_type_name_map;
26-
g_anytype_collection_name t_type_name_map;
27-
24+
2825
function get_columns_filter(
2926
a_exclude_xpath varchar2, a_include_xpath varchar2,
3027
a_table_alias varchar2 := 'ucd', a_column_alias varchar2 := 'item_data'
@@ -228,7 +225,6 @@ create or replace package body ut_compound_data_helper is
228225
end;
229226

230227
procedure generate_select_stmt(a_data_info ut_cursor_column,a_sql_stmt in out nocopy clob, a_col_name varchar2,a_alias varchar2 := 'ucd.') is
231-
l_sql_stmt clob;
232228
l_alias varchar2(10) := a_alias;
233229
l_col_syntax varchar2(4000);
234230
l_ut_owner varchar2(250) := ut_utils.ut_owner;
@@ -326,13 +322,14 @@ create or replace package body ut_compound_data_helper is
326322
end;
327323

328324

329-
function gen_compare_sql(a_inclusion_type boolean, a_is_negated boolean,a_unordered boolean,
330-
a_other ut_data_value_refcursor :=null, a_join_by_list ut_varchar2_list:=ut_varchar2_list() ) return clob is
325+
function gen_compare_sql(
326+
a_inclusion_type boolean, a_is_negated boolean, a_unordered boolean,
327+
a_other ut_data_value_refcursor := null, a_join_by_list ut_varchar2_list := ut_varchar2_list()
328+
) return clob is
331329
l_compare_sql clob;
332330
l_temp_string varchar2(32767);
333331

334332
l_xmltable_stmt clob;
335-
l_where_stmt clob;
336333
l_select_stmt clob;
337334
l_partition_stmt clob;
338335
l_equal_stmt clob;
@@ -780,35 +777,47 @@ create or replace package body ut_compound_data_helper is
780777
end if;
781778
end;
782779

783-
function is_collection (a_anytype_code in integer) return boolean is
780+
function get_column_type_desc(a_type_code in integer, a_dbms_sql_desc in boolean) return varchar2 is
784781
begin
785-
return a_anytype_code in (dbms_types.typecode_varray,dbms_types.typecode_table,dbms_types.typecode_namedcollection);
782+
return case when a_dbms_sql_desc then g_type_name_map(a_type_code) else g_anytype_name_map(a_type_code) end;
786783
end;
787784

788-
function is_collection (a_owner varchar2, a_type_name varchar2, a_anytype_code in integer :=null) return boolean is
789-
l_type_view varchar2(200) := ut_metadata.get_dba_view('dba_types');
790-
l_typecode varchar2(100);
791-
begin
792-
if a_anytype_code is null then
793-
execute immediate 'select typecode from '||l_type_view ||'
794-
where owner = :owner and type_name = :typename'
795-
into l_typecode using a_owner,a_type_name;
796-
797-
return l_typecode = 'COLLECTION';
798-
else
799-
return is_collection(a_anytype_code);
785+
function get_anytype_members_info( a_anytype anytype ) return t_anytype_members_rec is
786+
l_result t_anytype_members_rec;
787+
begin
788+
if a_anytype is not null then
789+
l_result.type_code := a_anytype.getinfo(
790+
prec => l_result.precision,
791+
scale => l_result.scale,
792+
len => l_result.length,
793+
csid => l_result.char_set_id,
794+
csfrm => l_result.char_set_frm,
795+
schema_name => l_result.schema_name,
796+
type_name => l_result.type_name,
797+
version => l_result.version,
798+
numelems => l_result.elements_count
799+
);
800800
end if;
801-
802-
exception
803-
when no_data_found then
804-
return false;
801+
return l_result;
805802
end;
806803

807-
function get_column_type_desc(a_type_code in integer, a_dbms_sql_desc in boolean) return varchar2 is
804+
function get_attr_elem_info( a_anytype anytype, a_pos pls_integer := null ) return t_anytype_elem_info_rec is
805+
l_result t_anytype_elem_info_rec;
808806
begin
809-
return case when a_dbms_sql_desc then g_type_name_map(a_type_code) else g_anytype_name_map(a_type_code) end;
807+
if a_anytype is not null then
808+
l_result.type_code := a_anytype.getattreleminfo(
809+
pos => a_pos,
810+
prec => l_result.precision,
811+
scale => l_result.scale,
812+
len => l_result.length,
813+
csid => l_result.char_set_id,
814+
csfrm => l_result.char_set_frm,
815+
attr_elt_type => l_result.attr_elt_type,
816+
aname => l_result.attribute_name
817+
);
818+
end if;
819+
return l_result;
810820
end;
811-
812821

813822
begin
814823
g_anytype_name_map(dbms_types.typecode_date) := 'DATE';

source/expectations/data_values/ut_compound_data_helper.pks

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,50 @@ create or replace package ut_compound_data_helper authid definer is
5454
exp_data_id raw(32),
5555
item_no number,
5656
dup_no number
57-
);
58-
57+
);
58+
59+
type t_anytype_members_rec is record (
60+
type_code pls_integer,
61+
schema_name varchar2(128),
62+
type_name varchar2(128),
63+
length pls_integer,
64+
elements_count pls_integer,
65+
version varchar2(32767),
66+
precision pls_integer,
67+
scale pls_integer,
68+
char_set_id pls_integer,
69+
char_set_frm pls_integer
70+
);
71+
72+
type t_anytype_elem_info_rec is record (
73+
type_code pls_integer,
74+
attribute_name varchar2(260),
75+
length pls_integer,
76+
version varchar2(32767),
77+
precision pls_integer,
78+
scale pls_integer,
79+
char_set_id pls_integer,
80+
char_set_frm pls_integer,
81+
attr_elt_type anytype
82+
);
83+
5984
type t_diff_tab is table of t_diff_rec;
6085

6186
function get_columns_filter(
6287
a_exclude_xpath varchar2, a_include_xpath varchar2,
6388
a_table_alias varchar2 := 'ucd', a_column_alias varchar2 := 'item_data'
6489
) return varchar2;
6590

66-
function get_columns_diff(a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab,a_order_enforced boolean := false)
67-
return tt_column_diffs;
91+
function get_columns_diff(
92+
a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab,a_order_enforced boolean := false
93+
) return tt_column_diffs;
6894

69-
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return clob;
95+
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return clob;
7096

71-
function get_rows_diff(
97+
function get_rows_diff(
7298
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
7399
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
74-
) return tt_row_diffs;
100+
) return tt_row_diffs;
75101

76102
function get_rows_diff_by_sql(a_act_cursor_info ut_cursor_column_tab,a_exp_cursor_info ut_cursor_column_tab,
77103
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
@@ -85,8 +111,10 @@ create or replace package ut_compound_data_helper authid definer is
85111

86112
function get_fixed_size_hash(a_string varchar2, a_base integer :=0,a_size integer :=9999999) return number;
87113

88-
function gen_compare_sql(a_inclusion_type boolean, a_is_negated boolean, a_unordered boolean,
89-
a_other ut_data_value_refcursor :=null, a_join_by_list ut_varchar2_list:=ut_varchar2_list() ) return clob;
114+
function gen_compare_sql(
115+
a_inclusion_type boolean, a_is_negated boolean, a_unordered boolean,
116+
a_other ut_data_value_refcursor :=null, a_join_by_list ut_varchar2_list:=ut_varchar2_list()
117+
) return clob;
90118

91119
procedure insert_diffs_result(a_diff_tab t_diff_tab, a_diff_id raw);
92120

@@ -96,28 +124,34 @@ create or replace package ut_compound_data_helper authid definer is
96124

97125
function get_rows_diff_count return integer;
98126

99-
function filter_out_cols(a_cursor_info ut_cursor_column_tab, a_current_list ut_varchar2_list,a_include boolean := true)
100-
return ut_cursor_column_tab;
127+
function filter_out_cols(
128+
a_cursor_info ut_cursor_column_tab, a_current_list ut_varchar2_list,a_include boolean := true
129+
) return ut_cursor_column_tab;
101130

102-
function get_missing_pk(a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab, a_current_list ut_varchar2_list)
103-
return tt_missing_pk;
131+
function get_missing_pk(
132+
a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab, a_current_list ut_varchar2_list
133+
) return tt_missing_pk;
104134

105-
function inc_exc_columns_from_cursor (a_cursor_info ut_cursor_column_tab, a_exclude_xpath ut_varchar2_list, a_include_xpath ut_varchar2_list)
106-
return ut_cursor_column_tab;
135+
function inc_exc_columns_from_cursor (
136+
a_cursor_info ut_cursor_column_tab, a_exclude_xpath ut_varchar2_list, a_include_xpath ut_varchar2_list
137+
) return ut_cursor_column_tab;
107138

108139
function contains_collection (a_cursor_info ut_cursor_column_tab) return number;
109140

110-
function remove_incomparable_cols( a_cursor_details ut_cursor_column_tab,a_incomparable_cols ut_varchar2_list) return ut_cursor_column_tab;
141+
function remove_incomparable_cols(
142+
a_cursor_details ut_cursor_column_tab,a_incomparable_cols ut_varchar2_list
143+
) return ut_cursor_column_tab;
111144

112145
function getxmlchildren(a_parent_name varchar2,a_cursor_table ut_cursor_column_tab) return xmltype;
113146

114147
function is_sql_compare_allowed(a_type_name varchar2) return boolean;
115148

116-
function is_collection (a_owner varchar2,a_type_name varchar2, a_anytype_code in integer :=null) return boolean;
149+
function get_column_type_desc(a_type_code in integer, a_dbms_sql_desc in boolean) return varchar2;
117150

118-
function is_collection (a_anytype_code in integer) return boolean;
119151

120-
function get_column_type_desc(a_type_code in integer, a_dbms_sql_desc in boolean) return varchar2;
121-
152+
function get_anytype_members_info( a_anytype anytype ) return t_anytype_members_rec;
153+
154+
function get_attr_elem_info( a_anytype anytype, a_pos pls_integer := null ) return t_anytype_elem_info_rec;
155+
122156
end;
123157
/

source/expectations/data_values/ut_compound_data_value.tpb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ create or replace type body ut_compound_data_value as
210210
begin
211211
l_other := treat(a_other as ut_compound_data_value);
212212
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_other.data_id);
213-
213+
-- dbms_output.put_line(ut_compound_data_helper.gen_compare_sql(
214+
-- a_inclusion_compare, a_is_negated, a_unordered,
215+
-- treat(a_other as ut_data_value_refcursor), a_join_by_list
216+
-- ));
214217
open l_loop_curs for
215218
ut_compound_data_helper.gen_compare_sql(
216219
a_inclusion_compare, a_is_negated, a_unordered,
Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
1-
create or replace type ut_cursor_column force authid current_user as object
2-
(
3-
parent_name varchar2(4000),
4-
access_path varchar2(4000),
5-
has_nested_col number(1,0),
6-
transformed_name varchar2(32),
7-
hierarchy_level number,
8-
column_position number,
9-
xml_valid_name varchar2(128),
10-
column_name varchar2(128),
11-
column_type varchar2(128),
12-
column_type_name varchar2(128),
13-
column_schema varchar2(128),
14-
column_len integer,
15-
is_sql_diffable number(1, 0),
16-
is_collection number(1, 0),
17-
18-
member procedure init(self in out nocopy ut_cursor_column,
19-
a_col_name varchar2, a_col_schema_name varchar2,
20-
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
21-
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2),
22-
23-
constructor function ut_cursor_column( self in out nocopy ut_cursor_column,
24-
a_col_name varchar2, a_col_schema_name varchar2,
25-
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
26-
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2)
27-
return self as result,
28-
29-
constructor function ut_cursor_column( self in out nocopy ut_cursor_column) return self as result
30-
)
31-
/
1+
create or replace type ut_cursor_column force authid current_user as object (
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2018 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
parent_name varchar2(4000),
19+
access_path varchar2(4000),
20+
has_nested_col number(1,0),
21+
transformed_name varchar2(32),
22+
hierarchy_level number,
23+
column_position number,
24+
xml_valid_name varchar2(128),
25+
column_name varchar2(128),
26+
column_type varchar2(128),
27+
column_type_name varchar2(128),
28+
column_schema varchar2(128),
29+
column_len integer,
30+
is_sql_diffable number(1, 0),
31+
is_collection number(1, 0),
32+
33+
member procedure init(self in out nocopy ut_cursor_column,
34+
a_col_name varchar2, a_col_schema_name varchar2,
35+
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
36+
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2),
37+
38+
constructor function ut_cursor_column( self in out nocopy ut_cursor_column,
39+
a_col_name varchar2, a_col_schema_name varchar2,
40+
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
41+
a_col_position integer, a_col_type in varchar2, a_collection integer, a_access_path in varchar2)
42+
return self as result,
43+
44+
constructor function ut_cursor_column( self in out nocopy ut_cursor_column) return self as result
45+
)
46+
/
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
create or replace type ut_cursor_column_tab as table of ut_cursor_column
1+
create or replace type ut_cursor_column_tab as
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2018 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
table of ut_cursor_column
219
/

0 commit comments

Comments
 (0)