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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cursor error handling
  • Loading branch information
lwasylow committed Apr 4, 2019
commit 90eb8c9109e471a6cf4ade7da30b511d2472537d
8 changes: 8 additions & 0 deletions source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -750,5 +750,13 @@ create or replace package body ut_utils is
return l_caller_stack_line;
end;

function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is
begin
return 'SQL exception thrown when fetching data from cursor: '||
remove_error_from_stack(sqlerrm,-19202)||chr(10)||
ut_expectation_processor.who_called_expectation(a_error_stack)||chr(10)||
'Check the query and data for errors.';
end;

end ut_utils;
/
5 changes: 5 additions & 0 deletions source/core/ut_utils.pks
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ create or replace package ut_utils authid definer is
gc_xml_processing constant pls_integer := -19202;
pragma exception_init (ex_xml_processing, -19202);

ex_failed_open_cur exception;
gc_failed_open_cur constant pls_integer := -20218;
pragma exception_init (ex_failed_open_cur, -20218);

gc_max_storage_varchar2_len constant integer := 4000;
gc_max_output_string_length constant integer := 4000;
gc_more_data_string constant varchar2(5) := '[...]';
Expand Down Expand Up @@ -378,6 +382,7 @@ create or replace package ut_utils authid definer is
*/
function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) return varchar2;

function create_err_cursor_msg(a_error_stack varchar2) return varchar2;

end ut_utils;
/
3 changes: 1 addition & 2 deletions source/expectations/data_values/ut_data_value_refcursor.tpb
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ create or replace type body ut_data_value_refcursor as
if l_cursor%isopen then
close l_cursor;
end if;
ut_expectation_processor.report_failure_no_caller('SQL exception thrown when fetching data from cursor: '||
ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)||'Check the query and data for errors.');
raise_application_error(ut_utils.gc_failed_open_cur,ut_utils.create_err_cursor_msg(dbms_utility.format_call_stack()));
when others then
if l_cursor%isopen then
close l_cursor;
Expand Down
43 changes: 7 additions & 36 deletions test/core/expectations/test_expectations_cursor.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -2484,60 +2484,31 @@ Diff:%

ut3.ut.expect(v_actual).to_equal(v_expected);
--Assert
l_expected_message := q'[%SQL exception thrown when fetching data from cursor:%
l_expected_message := q'[%ORA-20218: SQL exception thrown when fetching data from cursor:
%ORA-01722: invalid number%
%Check the query and data for errors.]';
at%ut.expect(v_actual).to_equal(v_expected)%]';

l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
--Assert
ut.expect(l_actual_message).to_be_like(l_expected_message);
end;

procedure xml_error_expected is
c_price CONSTANT NUMBER(20,4):= 1357;
c_user CONSTANT varchar2(30):= 'TEST_USER';
v_actual sys_refcursor;
v_expected sys_refcursor;
l_expected_message varchar2(32767);
l_actual_message varchar2(32767);
begin
open v_expected for
select cast(null as number(10)) as usd_price_amt, c_user as update_id
from dual where dummy = 1;
open v_actual for
select c_price as usd_price_amt, c_user as update_id from dual;

ut3.ut.expect(v_actual).to_equal(v_expected);
--Assert
l_expected_message := q'[%SQL exception thrown when fetching data from cursor:%
%ORA-01722: invalid number%
%Check the query and data for errors.]';

l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
--Assert
ut.expect(l_actual_message).to_be_like(l_expected_message);
end;

procedure xml_error_both is
c_price CONSTANT NUMBER(20,4):= 1357;
c_user CONSTANT varchar2(30):= 'TEST_USER';
v_actual sys_refcursor;
v_expected sys_refcursor;
l_expected_message varchar2(32767);
l_actual_message varchar2(32767);
begin
select 1/0 as test from dual;
open v_actual for
select cast(null as number(10)) as usd_price_amt, c_user as update_id
from dual where dummy = 1;
open v_expected for
select cast(null as number(10)) as usd_price_amt, c_user as update_id
from dual where dummy = 1;
select 1 as test from dual;

ut3.ut.expect(v_actual).to_equal(v_expected);
--Assert
l_expected_message := q'[%SQL exception thrown when fetching data from cursor:%
%ORA-01722: invalid number%
%Check the query and data for errors.]';
l_expected_message := q'[%ORA-20218: SQL exception thrown when fetching data from cursor:
%ORA-01476: divisor is equal to zero%
%at % ut.expect(v_actual).to_equal(v_expected)%]';

l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
--Assert
Expand Down
5 changes: 1 addition & 4 deletions test/core/expectations/test_expectations_cursor.pks
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,6 @@ create or replace package test_expectations_cursor is

--%test(Fail to process a cursor for expected)
procedure xml_error_expected;

--%test(Fail to process a cursor for both)
procedure xml_error_both;


end;
/