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

Skip to content

Commit 898bec2

Browse files
committed
Fixed support for different DATE NLS settings.
1 parent 3e4e1a8 commit 898bec2

5 files changed

Lines changed: 8 additions & 14 deletions

File tree

docs/userguide/expectations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ Due to the way Oracle handles DATE data type when converting from cursor data to
10041004
The NLS_DATE_FORMAT setting from the moment the cursor was opened determines the formatting of dates used for cursor data comparison.
10051005
By default, Oracle NLS_DATE_FORMAT is timeless, so data of DATE datatype, will be compared ignoring the time component.
10061006

1007-
You should use procedures `ut.set_nls`, `ut.reset_nls` around cursors that you want to compare in your tests.
1007+
You should surround cursors and expectations with procedures `ut.set_nls`, `ut.reset_nls`.
10081008
This way, the DATE data in cursors will be properly formatted for comparison using date-time format.
10091009

10101010
The example below makes use of `ut.set_nls`, `ut.reset_nls`, so that the date in `l_expected` and `l_actual` is compared using date-time formatting.
@@ -1048,9 +1048,9 @@ create or replace package body test_get_events is
10481048
open l_expected_bad_date for select gc_description as description, gc_event_date + gc_second as event_date from dual;
10491049
--Act
10501050
l_actual := get_events();
1051-
ut.reset_nls(); -- Change the NLS settings after cursors were opened
10521051
--Assert
10531052
ut.expect( l_actual ).not_to_equal( l_expected_bad_date );
1053+
ut.reset_nls(); -- Change the NLS settings after cursors were opened
10541054
end;
10551055

10561056
procedure bad_test is

source/core/ut_expectation_processor.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ create or replace package body ut_expectation_processor as
9696
bulk collect into l_session_params
9797
from nls_session_parameters nsp
9898
where parameter
99-
in ( 'NLS_DATE_FORMAT', 'NLS_TIMESTAMP_FORMAT', 'NLS_TIMESTAMP_TZ_FORMAT');
99+
in ( 'NLS_DATE_FORMAT', 'NLS_TIMESTAMP_FORMAT', 'NLS_TIMESTAMP_TZ_FORMAT')
100+
order by 1;
100101

101102
return l_session_params;
102103
end;
@@ -113,7 +114,6 @@ create or replace package body ut_expectation_processor as
113114
when insuf_privs then NULL;
114115
end;
115116

116-
execute immediate 'alter session set nls_date_format = '''||ut_utils.gc_date_format||'''';
117117
execute immediate 'alter session set nls_timestamp_format = '''||ut_utils.gc_timestamp_format||'''';
118118
execute immediate 'alter session set nls_timestamp_tz_format = '''||ut_utils.gc_timestamp_tz_format||'''';
119119
end;

source/expectations/data_values/ut_compound_data_helper.pkb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ create or replace package body ut_compound_data_helper is
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 ;
209209
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;
210+
l_col_syntax := 'to_date('||l_alias||a_data_info.transformed_name||') as '|| a_data_info.transformed_name;
211211
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('TIMESTAMP') then
212212
l_col_syntax := 'to_timestamp('||l_alias||a_data_info.transformed_name||','''||ut_utils.gc_timestamp_format||''') as '|| a_data_info.transformed_name;
213213
elsif a_data_info.is_sql_diffable = 1 and a_data_info.column_type in ('TIMESTAMP WITH TIME ZONE') then

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,12 @@ create or replace type body ut_data_value_refcursor as
305305
begin
306306
l_diff_id := ut_compound_data_helper.get_hash(a_self.data_id||a_other.data_id);
307307

308-
--Set NLS settings to handle extract of date from xml
309-
ut_expectation_processor.set_xml_nls_params();
310-
311308
begin
312309
open l_cursor for a_diff_cursor_text using a_self.data_id, a_other.data_id;
313310
--fetch and save rows for display of diff
314311
fetch l_cursor bulk collect into l_diff_tab limit ut_utils.gc_diff_max_rows;
315312

316-
--Reset parameters back
317-
ut_expectation_processor.reset_nls_params();
318313
exception when others then
319-
ut_expectation_processor.reset_nls_params();
320314
if l_cursor%isopen then
321315
close l_cursor;
322316
end if;

test/core/expectations/test_expectations_cursor.pkb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ create or replace package body test_expectations_cursor is
6262
l_actual sys_refcursor;
6363
begin
6464
-- Arrange
65-
ut.set_nls;
65+
ut3.ut.set_nls;
6666
open l_expected for
6767
select 1 as my_num,
6868
'This is my test string' as my_string,
@@ -75,11 +75,11 @@ create or replace package body test_expectations_cursor is
7575
to_clob('This is an even longer test clob') as my_clob,
7676
to_date('1984-09-05', 'YYYY-MM-DD') as my_date
7777
from dual;
78-
ut.reset_nls;
7978
--Act
8079
ut3.ut.expect( l_actual ).to_equal( l_expected );
8180
--Assert
8281
ut.expect(expectations.failed_expectations_data()).to_be_empty();
82+
ut3.ut.reset_nls;
8383
end;
8484

8585
procedure success_on_empty
@@ -404,11 +404,11 @@ create or replace package body test_expectations_cursor is
404404
ut3.ut.set_nls;
405405
open l_actual for select l_date as some_date from dual;
406406
open l_expected for select l_date-l_second some_date from dual;
407-
ut3.ut.reset_nls;
408407
--Act
409408
ut3.ut.expect( l_actual ).to_equal( l_expected );
410409
--Assert
411410
ut.expect(expectations.failed_expectations_data()).not_to_be_empty();
411+
ut3.ut.reset_nls;
412412
end;
413413

414414
procedure uses_default_nls_for_date

0 commit comments

Comments
 (0)