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

Skip to content

Commit 4d55bf4

Browse files
authored
Merge pull request #1179 from utPLSQL/feature/1082_failure_when_comparing_nested_objects
Feature/1082 failure when comparing nested objects
2 parents e358037 + b11e799 commit 4d55bf4

13 files changed

Lines changed: 373 additions & 9 deletions

source/core/ut_utils.pkb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,12 +882,14 @@ create or replace package body ut_utils is
882882

883883
function get_hash(a_data raw, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash is
884884
begin
885-
return dbms_crypto.hash(a_data, a_hash_type);
885+
--We cannot run hash on null
886+
return case when a_data is null then null else dbms_crypto.hash(a_data, a_hash_type) end;
886887
end;
887888

888889
function get_hash(a_data clob, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash is
889890
begin
890-
return dbms_crypto.hash(a_data, a_hash_type);
891+
--We cannot run hash on null
892+
return case when a_data is null then null else dbms_crypto.hash(a_data, a_hash_type) end;
891893
end;
892894

893895
function qualified_sql_name(a_name varchar2) return varchar2 is

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ create or replace package body ut_compound_data_helper is
278278
begin
279279
if a_data_info is not empty then
280280
for i in 1..a_data_info.count loop
281-
if a_data_info(i).has_nested_col = 0 then
281+
if a_data_info(i).has_nested_col = 0 and a_data_info(i).column_type <> 'OBJECT' then
282282
--Get XMLTABLE column list
283283
add_element_to_list(l_xmltab_list,generate_xmltab_stmt(a_data_info(i)));
284284
--Get Select statment list of columns
@@ -398,8 +398,12 @@ create or replace package body ut_compound_data_helper is
398398
l_column_list ut_varchar2_list := ut_varchar2_list();
399399
begin
400400
for i in 1..a_cursor_info.count loop
401-
l_column_list.extend;
402-
l_column_list(l_column_list.last) := a_cursor_info(i).access_path;
401+
--This avoids extracting single columns from nested objects.
402+
--as we can go down to any level but we will lose visibility of parent.
403+
if a_cursor_info(i).hierarchy_level = 1 then
404+
l_column_list.extend;
405+
l_column_list(l_column_list.last) := a_cursor_info(i).access_path;
406+
end if;
403407
end loop;
404408
return l_column_list;
405409
end;

source/expectations/data_values/ut_cursor_column.tpb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ create or replace type body ut_cursor_column as
1414
self.column_len := a_col_max_len; --length of column
1515
self.column_precision := a_col_precision;
1616
self.column_scale := a_col_scale;
17-
self.column_name := TRIM( BOTH '''' FROM a_col_name); --name of the column
1817
self.column_type_name := coalesce(a_col_type_name,a_col_type); --type name e.g. test_dummy_object or varchar2
18+
self.column_name := case when a_col_name is null and a_collection = 1 then
19+
self.column_type_name
20+
else TRIM( BOTH '''' FROM a_col_name)
21+
end; --name of the column, however in nested object for collection name is not defined in cursor.
1922
self.xml_valid_name := ut_utils.get_valid_xml_name(self.column_name);
2023
self.display_path := case when a_access_path is null then
2124
self.column_name
@@ -25,15 +28,16 @@ create or replace type body ut_cursor_column as
2528
self.access_path := case when a_access_path is null then
2629
self.xml_valid_name
2730
else
28-
a_access_path||'/'||self.xml_valid_name
31+
a_access_path||'/'||self.xml_valid_name
2932
end; --Access path used for XMLTABLE query
3033
self.filter_path := '/'||self.access_path; --Filter path will differ from access path in anydata type
34+
--Transformed name needs to be build on full access path to avoid ambiguity when there is 3 or more levels of nesting.
3135
self.transformed_name := case when length(self.xml_valid_name) > 30 then
32-
'"'||ut_compound_data_helper.get_fixed_size_hash(self.parent_name||self.xml_valid_name)||'"'
36+
'"'||ut_compound_data_helper.get_fixed_size_hash(self.access_path)||'"'
3337
when self.parent_name is null then
3438
'"'||self.xml_valid_name||'"'
3539
else
36-
'"'||ut_compound_data_helper.get_fixed_size_hash(self.parent_name||self.xml_valid_name)||'"'
40+
'"'||ut_compound_data_helper.get_fixed_size_hash(self.access_path)||'"'
3741
end; --when is nestd we need to hash name to make sure we dont exceed 30 char
3842
self.column_type := a_col_type; --column type e.g. user_defined , varchar2
3943
self.column_schema := a_col_schema_name; -- schema name

test/install_ut3_tester_helper.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@ alter session set plsql_optimize_level=0;
66
--Install ut3_tester_helper
77
@@ut3_tester_helper/test_dummy_object.tps
88
@@ut3_tester_helper/other_dummy_object.tps
9+
@@ut3_tester_helper/test_dummy_nested_object.tps
10+
@@ut3_tester_helper/test_dummy_double_nested_object.tps
911
@@ut3_tester_helper/test_dummy_object_list.tps
12+
@@ut3_tester_helper/test_dummy_nested_object_list.tps
13+
@@ut3_tester_helper/test_dummy_double_nested_list.tps
14+
@@ut3_tester_helper/test_dummy_dble_nest_lst_obj.tps
1015
@@ut3_tester_helper/test_tab_varchar2.tps
1116
@@ut3_tester_helper/test_tab_varray.tps
17+
@@ut3_tester_helper/test_nested_tab_varray.tps
1218
@@ut3_tester_helper/test_dummy_number.tps
1319
@@ut3_tester_helper/ut_test_table.sql
1420
@@ut3_tester_helper/test_event_object.tps
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
declare
2+
l_exists integer;
3+
begin
4+
select count(1) into l_exists from user_types where type_name = 'TEST_DUMMY_DBLE_NEST_LST_OBJ';
5+
if l_exists > 0 then
6+
execute immediate 'drop type test_dummy_dble_nest_lst_obj force';
7+
end if;
8+
end;
9+
/
10+
11+
CREATE TYPE test_dummy_dble_nest_lst_obj AS OBJECT
12+
(
13+
some_number_id NUMBER,
14+
some_name VARCHAR2 (25),
15+
dummy_list test_dummy_double_nested_list
16+
);
17+
/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
declare
2+
l_exists integer;
3+
begin
4+
select count(1) into l_exists from user_types where type_name = 'TEST_DUMMY_DOUBLE_NESTED_LIST';
5+
if l_exists > 0 then
6+
execute immediate 'drop type test_dummy_double_nested_list force';
7+
end if;
8+
end;
9+
/
10+
11+
CREATE TYPE test_dummy_double_nested_list AS
12+
TABLE OF test_dummy_nested_object_list;
13+
/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
declare
2+
l_exists integer;
3+
begin
4+
select count(1) into l_exists from user_types where type_name = 'TEST_DUMMY_DOUBLE_NESTED_OBJ';
5+
if l_exists > 0 then
6+
execute immediate 'drop type test_dummy_double_nested_obj force';
7+
end if;
8+
end;
9+
/
10+
11+
create or replace type test_dummy_double_nested_obj as object (
12+
first_double_nested_obj test_dummy_nested_object,
13+
"Value" varchar2(30)
14+
)
15+
/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
declare
2+
l_exists integer;
3+
begin
4+
select count(1) into l_exists from user_types where type_name = 'TEST_DUMMY_NESTED_OBJECT';
5+
if l_exists > 0 then
6+
execute immediate 'drop type test_dummy_nested_object force';
7+
end if;
8+
end;
9+
/
10+
11+
create or replace type test_dummy_nested_object as object (
12+
first_nested_obj test_dummy_object,
13+
sec_nested_obj test_dummy_object
14+
)
15+
/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
declare
2+
l_exists integer;
3+
begin
4+
select count(1) into l_exists from user_types where type_name = 'TEST_DUMMY_NESTED_OBJECT_LIST';
5+
if l_exists > 0 then
6+
execute immediate 'drop type test_dummy_nested_object_list force';
7+
end if;
8+
end;
9+
/
10+
11+
create or replace type test_dummy_nested_object_list as object (
12+
first_nested_obj test_dummy_object_list,
13+
somename varchar2(50)
14+
)
15+
/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1+
declare
2+
l_exists integer;
3+
begin
4+
select count(1) into l_exists from user_types where type_name = 'TEST_DUMMY_OBJECT_LIST';
5+
if l_exists > 0 then
6+
execute immediate 'drop type test_dummy_object_list force';
7+
end if;
8+
end;
9+
/
10+
111
create or replace type test_dummy_object_list as table of test_dummy_object
212
/

0 commit comments

Comments
 (0)