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

Skip to content

Commit 90eb8c9

Browse files
committed
Cursor error handling
1 parent a697e1d commit 90eb8c9

5 files changed

Lines changed: 22 additions & 42 deletions

File tree

source/core/ut_utils.pkb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,5 +750,13 @@ create or replace package body ut_utils is
750750
return l_caller_stack_line;
751751
end;
752752

753+
function create_err_cursor_msg(a_error_stack varchar2) return varchar2 is
754+
begin
755+
return 'SQL exception thrown when fetching data from cursor: '||
756+
remove_error_from_stack(sqlerrm,-19202)||chr(10)||
757+
ut_expectation_processor.who_called_expectation(a_error_stack)||chr(10)||
758+
'Check the query and data for errors.';
759+
end;
760+
753761
end ut_utils;
754762
/

source/core/ut_utils.pks

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ create or replace package ut_utils authid definer is
113113
gc_xml_processing constant pls_integer := -19202;
114114
pragma exception_init (ex_xml_processing, -19202);
115115

116+
ex_failed_open_cur exception;
117+
gc_failed_open_cur constant pls_integer := -20218;
118+
pragma exception_init (ex_failed_open_cur, -20218);
119+
116120
gc_max_storage_varchar2_len constant integer := 4000;
117121
gc_max_output_string_length constant integer := 4000;
118122
gc_more_data_string constant varchar2(5) := '[...]';
@@ -378,6 +382,7 @@ create or replace package ut_utils authid definer is
378382
*/
379383
function remove_error_from_stack(a_error_stack varchar2, a_ora_code number) return varchar2;
380384

385+
function create_err_cursor_msg(a_error_stack varchar2) return varchar2;
381386

382387
end ut_utils;
383388
/

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ create or replace type body ut_data_value_refcursor as
100100
if l_cursor%isopen then
101101
close l_cursor;
102102
end if;
103-
ut_expectation_processor.report_failure_no_caller('SQL exception thrown when fetching data from cursor: '||
104-
ut_utils.remove_error_from_stack(sqlerrm,-19202)||chr(10)||'Check the query and data for errors.');
103+
raise_application_error(ut_utils.gc_failed_open_cur,ut_utils.create_err_cursor_msg(dbms_utility.format_call_stack()));
105104
when others then
106105
if l_cursor%isopen then
107106
close l_cursor;

test/core/expectations/test_expectations_cursor.pkb

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,60 +2484,31 @@ Diff:%
24842484

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

24912491
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
24922492
--Assert
24932493
ut.expect(l_actual_message).to_be_like(l_expected_message);
24942494
end;
24952495

24962496
procedure xml_error_expected is
2497-
c_price CONSTANT NUMBER(20,4):= 1357;
2498-
c_user CONSTANT varchar2(30):= 'TEST_USER';
24992497
v_actual sys_refcursor;
25002498
v_expected sys_refcursor;
25012499
l_expected_message varchar2(32767);
25022500
l_actual_message varchar2(32767);
25032501
begin
25042502
open v_expected for
2505-
select cast(null as number(10)) as usd_price_amt, c_user as update_id
2506-
from dual where dummy = 1;
2507-
open v_actual for
2508-
select c_price as usd_price_amt, c_user as update_id from dual;
2509-
2510-
ut3.ut.expect(v_actual).to_equal(v_expected);
2511-
--Assert
2512-
l_expected_message := q'[%SQL exception thrown when fetching data from cursor:%
2513-
%ORA-01722: invalid number%
2514-
%Check the query and data for errors.]';
2515-
2516-
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
2517-
--Assert
2518-
ut.expect(l_actual_message).to_be_like(l_expected_message);
2519-
end;
2520-
2521-
procedure xml_error_both is
2522-
c_price CONSTANT NUMBER(20,4):= 1357;
2523-
c_user CONSTANT varchar2(30):= 'TEST_USER';
2524-
v_actual sys_refcursor;
2525-
v_expected sys_refcursor;
2526-
l_expected_message varchar2(32767);
2527-
l_actual_message varchar2(32767);
2528-
begin
2503+
select 1/0 as test from dual;
25292504
open v_actual for
2530-
select cast(null as number(10)) as usd_price_amt, c_user as update_id
2531-
from dual where dummy = 1;
2532-
open v_expected for
2533-
select cast(null as number(10)) as usd_price_amt, c_user as update_id
2534-
from dual where dummy = 1;
2505+
select 1 as test from dual;
25352506

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

25422513
l_actual_message := ut3.ut_expectation_processor.get_failed_expectations()(1).message;
25432514
--Assert

test/core/expectations/test_expectations_cursor.pks

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,6 @@ create or replace package test_expectations_cursor is
396396

397397
--%test(Fail to process a cursor for expected)
398398
procedure xml_error_expected;
399-
400-
--%test(Fail to process a cursor for both)
401-
procedure xml_error_both;
402-
399+
403400
end;
404401
/

0 commit comments

Comments
 (0)