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

Skip to content

Commit 3e4e1a8

Browse files
committed
Fixing a conversion of date when extracting XML DATE,TS, TS_TZ,TS_LTS using XMLTABLE.
1 parent 3aa872b commit 3e4e1a8

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ create or replace package body ut_compound_data_helper is
206206
begin
207207
if a_data_info.is_sql_diffable = 0 then
208208
l_col_syntax := l_ut_owner ||'.ut_compound_data_helper.get_hash('||l_alias||a_data_info.transformed_name||'.getClobVal()) as '||a_data_info.transformed_name ;
209+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type = 'DATE' then
210+
l_col_syntax := 'to_date('||l_alias||a_data_info.transformed_name||','''||ut_utils.gc_date_format||''') as '|| a_data_info.transformed_name;
211+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('TIMESTAMP') then
212+
l_col_syntax := 'to_timestamp('||l_alias||a_data_info.transformed_name||','''||ut_utils.gc_timestamp_format||''') as '|| a_data_info.transformed_name;
213+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('TIMESTAMP WITH TIME ZONE') then
214+
l_col_syntax := 'to_timestamp_tz('||l_alias||a_data_info.transformed_name||','''||ut_utils.gc_timestamp_tz_format||''') as '|| a_data_info.transformed_name;
215+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('TIMESTAMP WITH LOCAL TIME ZONE') then
216+
l_col_syntax := ' cast( to_timestamp_tz('||l_alias||a_data_info.transformed_name||','''||ut_utils.gc_timestamp_tz_format||''') AS TIMESTAMP WITH LOCAL TIME ZONE) as '|| a_data_info.transformed_name;
209217
else
210218
l_col_syntax := l_alias||a_data_info.transformed_name||' as '|| a_data_info.transformed_name;
211219
end if;
@@ -217,12 +225,8 @@ create or replace package body ut_compound_data_helper is
217225
begin
218226
if a_data_info.is_sql_diffable = 0 then
219227
l_col_type := 'XMLTYPE';
220-
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type = 'DATE' then
221-
l_col_type := 'TIMESTAMP';
222-
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('TIMESTAMP','TIMESTAMP WITH TIME ZONE') then
223-
l_col_type := a_data_info.column_type;
224-
--TODO : Oracle bug : https://community.oracle.com/thread/1957521
225-
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type = 'TIMESTAMP WITH LOCAL TIME ZONE' then
228+
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('DATE','TIMESTAMP','TIMESTAMP WITH TIME ZONE',
229+
'TIMESTAMP WITH LOCAL TIME ZONE') then
226230
l_col_type := 'VARCHAR2(50)';
227231
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('INTERVAL DAY TO SECOND','INTERVAL YEAR TO MONTH') then
228232
l_col_type := a_data_info.column_type;
@@ -370,7 +374,6 @@ create or replace package body ut_compound_data_helper is
370374
end if;
371375

372376
l_compare_sql := replace(l_compare_sql,'{:where_condition:}',l_where_stmt);
373-
374377
return l_compare_sql;
375378
end;
376379

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,25 @@ create or replace type body ut_data_value_refcursor as
304304
l_diif_rowcount integer :=0;
305305
begin
306306
l_diff_id := ut_compound_data_helper.get_hash(a_self.data_id||a_other.data_id);
307-
open l_cursor for a_diff_cursor_text using a_self.data_id, a_other.data_id;
308-
--fetch and save rows for display of diff
309-
fetch l_cursor bulk collect into l_diff_tab limit ut_utils.gc_diff_max_rows;
307+
308+
--Set NLS settings to handle extract of date from xml
309+
ut_expectation_processor.set_xml_nls_params();
310+
311+
begin
312+
open l_cursor for a_diff_cursor_text using a_self.data_id, a_other.data_id;
313+
--fetch and save rows for display of diff
314+
fetch l_cursor bulk collect into l_diff_tab limit ut_utils.gc_diff_max_rows;
315+
316+
--Reset parameters back
317+
ut_expectation_processor.reset_nls_params();
318+
exception when others then
319+
ut_expectation_processor.reset_nls_params();
320+
if l_cursor%isopen then
321+
close l_cursor;
322+
end if;
323+
raise;
324+
end;
325+
310326
ut_compound_data_helper.insert_diffs_result( l_diff_tab, l_diff_id );
311327
--fetch rows for count only
312328
loop

0 commit comments

Comments
 (0)