Skip to content

Commit

Permalink
Refactoring recursive calls for resolving complex types in cursor.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgebal committed Dec 10, 2018
1 parent ca9f8eb commit 8e42ef5
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 260 deletions.
62 changes: 37 additions & 25 deletions source/expectations/data_values/ut_compound_data_helper.pkb
Expand Up @@ -228,7 +228,6 @@ create or replace package body ut_compound_data_helper is
end;

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
l_sql_stmt clob;
l_alias varchar2(10) := a_alias;
l_col_syntax varchar2(4000);
l_ut_owner varchar2(250) := ut_utils.ut_owner;
Expand Down Expand Up @@ -326,13 +325,14 @@ create or replace package body ut_compound_data_helper is
end;


function gen_compare_sql(a_inclusion_type boolean, a_is_negated boolean,a_unordered boolean,
a_other ut_data_value_refcursor :=null, a_join_by_list ut_varchar2_list:=ut_varchar2_list() ) return clob is
function gen_compare_sql(
a_inclusion_type boolean, a_is_negated boolean, a_unordered boolean,
a_other ut_data_value_refcursor := null, a_join_by_list ut_varchar2_list := ut_varchar2_list()
) return clob is
l_compare_sql clob;
l_temp_string varchar2(32767);

l_xmltable_stmt clob;
l_where_stmt clob;
l_select_stmt clob;
l_partition_stmt clob;
l_equal_stmt clob;
Expand Down Expand Up @@ -780,35 +780,47 @@ create or replace package body ut_compound_data_helper is
end if;
end;

function is_collection (a_anytype_code in integer) return boolean is
function get_column_type_desc(a_type_code in integer, a_dbms_sql_desc in boolean) return varchar2 is
begin
return a_anytype_code in (dbms_types.typecode_varray,dbms_types.typecode_table,dbms_types.typecode_namedcollection);
return case when a_dbms_sql_desc then g_type_name_map(a_type_code) else g_anytype_name_map(a_type_code) end;
end;

function is_collection (a_owner varchar2, a_type_name varchar2, a_anytype_code in integer :=null) return boolean is
l_type_view varchar2(200) := ut_metadata.get_dba_view('dba_types');
l_typecode varchar2(100);
begin
if a_anytype_code is null then
execute immediate 'select typecode from '||l_type_view ||'
where owner = :owner and type_name = :typename'
into l_typecode using a_owner,a_type_name;

return l_typecode = 'COLLECTION';
else
return is_collection(a_anytype_code);
function get_anytype_members_info( a_anytype anytype ) return t_anytype_members_rec is
l_result t_anytype_members_rec;
begin
if a_anytype is not null then
l_result.type_code := a_anytype.getinfo(
prec => l_result.precision,
scale => l_result.scale,
len => l_result.length,
csid => l_result.char_set_id,
csfrm => l_result.char_set_frm,
schema_name => l_result.schema_name,
type_name => l_result.type_name,
version => l_result.version,
numelems => l_result.elements_count
);
end if;

exception
when no_data_found then
return false;
return l_result;
end;

function get_column_type_desc(a_type_code in integer, a_dbms_sql_desc in boolean) return varchar2 is
function get_attr_elem_info( a_anytype anytype, a_pos pls_integer ) return t_anytype_elem_info_rec is
l_result t_anytype_elem_info_rec;
begin
return case when a_dbms_sql_desc then g_type_name_map(a_type_code) else g_anytype_name_map(a_type_code) end;
if a_anytype is not null then
l_result.type_code := a_anytype.getattreleminfo(
pos => a_pos,
prec => l_result.precision,
scale => l_result.scale,
len => l_result.length,
csid => l_result.char_set_id,
csfrm => l_result.char_set_frm,
attr_elt_type => l_result.attr_elt_type,
aname => l_result.attribute_name
);
end if;
return l_result;
end;


begin
g_anytype_name_map(dbms_types.typecode_date) := 'DATE';
Expand Down
79 changes: 59 additions & 20 deletions source/expectations/data_values/ut_compound_data_helper.pks
Expand Up @@ -54,24 +54,50 @@ create or replace package ut_compound_data_helper authid definer is
exp_data_id raw(32),
item_no number,
dup_no number
);

);

type t_anytype_members_rec is record (
type_code pls_integer,
schema_name varchar2(128),
type_name varchar2(128),
length pls_integer,
elements_count pls_integer,
version varchar2(32767),
precision pls_integer,
scale pls_integer,
char_set_id pls_integer,
char_set_frm pls_integer
);

type t_anytype_elem_info_rec is record (
type_code pls_integer,
attribute_name varchar2(260),
length pls_integer,
version varchar2(32767),
precision pls_integer,
scale pls_integer,
char_set_id pls_integer,
char_set_frm pls_integer,
attr_elt_type anytype
);

type t_diff_tab is table of t_diff_rec;

function get_columns_filter(
a_exclude_xpath varchar2, a_include_xpath varchar2,
a_table_alias varchar2 := 'ucd', a_column_alias varchar2 := 'item_data'
) return varchar2;

function get_columns_diff(a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab,a_order_enforced boolean := false)
return tt_column_diffs;
function get_columns_diff(
a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab,a_order_enforced boolean := false
) return tt_column_diffs;

function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return clob;
function get_pk_value (a_join_by_xpath varchar2,a_item_data xmltype) return clob;

function get_rows_diff(
function get_rows_diff(
a_expected_dataset_guid raw, a_actual_dataset_guid raw, a_diff_id raw,
a_max_rows integer, a_exclude_xpath varchar2, a_include_xpath varchar2
) return tt_row_diffs;
) return tt_row_diffs;

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

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

function gen_compare_sql(a_inclusion_type boolean, a_is_negated boolean, a_unordered boolean,
a_other ut_data_value_refcursor :=null, a_join_by_list ut_varchar2_list:=ut_varchar2_list() ) return clob;
function gen_compare_sql(
a_inclusion_type boolean, a_is_negated boolean, a_unordered boolean,
a_other ut_data_value_refcursor :=null, a_join_by_list ut_varchar2_list:=ut_varchar2_list()
) return clob;

procedure insert_diffs_result(a_diff_tab t_diff_tab, a_diff_id raw);

Expand All @@ -96,28 +124,39 @@ create or replace package ut_compound_data_helper authid definer is

function get_rows_diff_count return integer;

function filter_out_cols(a_cursor_info ut_cursor_column_tab, a_current_list ut_varchar2_list,a_include boolean := true)
return ut_cursor_column_tab;
function filter_out_cols(
a_cursor_info ut_cursor_column_tab, a_current_list ut_varchar2_list,a_include boolean := true
) return ut_cursor_column_tab;

function get_missing_pk(a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab, a_current_list ut_varchar2_list)
return tt_missing_pk;
function get_missing_pk(
a_expected ut_cursor_column_tab, a_actual ut_cursor_column_tab, a_current_list ut_varchar2_list
) return tt_missing_pk;

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)
return ut_cursor_column_tab;
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
) return ut_cursor_column_tab;

function contains_collection (a_cursor_info ut_cursor_column_tab) return number;

function remove_incomparable_cols( a_cursor_details ut_cursor_column_tab,a_incomparable_cols ut_varchar2_list) return ut_cursor_column_tab;
function remove_incomparable_cols(
a_cursor_details ut_cursor_column_tab,a_incomparable_cols ut_varchar2_list
) return ut_cursor_column_tab;

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

function is_sql_compare_allowed(a_type_name varchar2) return boolean;

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

function is_collection (a_anytype_code in integer) return boolean;

function get_column_type_desc(a_type_code in integer, a_dbms_sql_desc in boolean) return varchar2;

function get_anytype_members_info(
a_anytype anytype
) return t_anytype_members_rec;

function get_attr_elem_info(
a_anytype anytype,
a_pos pls_integer
) return t_anytype_elem_info_rec;

end;
/
5 changes: 4 additions & 1 deletion source/expectations/data_values/ut_compound_data_value.tpb
Expand Up @@ -210,7 +210,10 @@ create or replace type body ut_compound_data_value as
begin
l_other := treat(a_other as ut_compound_data_value);
l_diff_id := ut_compound_data_helper.get_hash(self.data_id||l_other.data_id);

dbms_output.put_line(ut_compound_data_helper.gen_compare_sql(
a_inclusion_compare, a_is_negated, a_unordered,
treat(a_other as ut_data_value_refcursor), a_join_by_list
));
open l_loop_curs for
ut_compound_data_helper.gen_compare_sql(
a_inclusion_compare, a_is_negated, a_unordered,
Expand Down
77 changes: 46 additions & 31 deletions source/expectations/data_values/ut_cursor_column.tps
@@ -1,31 +1,46 @@
create or replace type ut_cursor_column force authid current_user as object
(
parent_name varchar2(4000),
access_path varchar2(4000),
has_nested_col number(1,0),
transformed_name varchar2(32),
hierarchy_level number,
column_position number,
xml_valid_name varchar2(128),
column_name varchar2(128),
column_type varchar2(128),
column_type_name varchar2(128),
column_schema varchar2(128),
column_len integer,
is_sql_diffable number(1, 0),
is_collection number(1, 0),

member procedure init(self in out nocopy ut_cursor_column,
a_col_name varchar2, a_col_schema_name varchar2,
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2),

constructor function ut_cursor_column( self in out nocopy ut_cursor_column,
a_col_name varchar2, a_col_schema_name varchar2,
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2)
return self as result,

constructor function ut_cursor_column( self in out nocopy ut_cursor_column) return self as result
)
/
create or replace type ut_cursor_column force authid current_user as object (
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
parent_name varchar2(4000),
access_path varchar2(4000),
has_nested_col number(1,0),
transformed_name varchar2(32),
hierarchy_level number,
column_position number,
xml_valid_name varchar2(128),
column_name varchar2(128),
column_type varchar2(128),
column_type_name varchar2(128),
column_schema varchar2(128),
column_len integer,
is_sql_diffable number(1, 0),
is_collection number(1, 0),

member procedure init(self in out nocopy ut_cursor_column,
a_col_name varchar2, a_col_schema_name varchar2,
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
a_col_position integer, a_col_type in varchar2, a_collection integer,a_access_path in varchar2),

constructor function ut_cursor_column( self in out nocopy ut_cursor_column,
a_col_name varchar2, a_col_schema_name varchar2,
a_col_type_name varchar2, a_col_max_len integer, a_parent_name varchar2 := null, a_hierarchy_level integer := 1,
a_col_position integer, a_col_type in varchar2, a_collection integer, a_access_path in varchar2)
return self as result,

constructor function ut_cursor_column( self in out nocopy ut_cursor_column) return self as result
)
/
19 changes: 18 additions & 1 deletion source/expectations/data_values/ut_cursor_column_tab.tps
@@ -1,2 +1,19 @@
create or replace type ut_cursor_column_tab as table of ut_cursor_column
create or replace type ut_cursor_column_tab as
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
table of ut_cursor_column
/

0 comments on commit 8e42ef5

Please sign in to comment.