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

Skip to content

Commit ced146b

Browse files
authored
Merge pull request #858 from utPLSQL/fix/4k_block_issue
Modify a code to fail when inserting a suitepath over 1k long.
2 parents 64a4581 + 204a4cd commit ced146b

6 files changed

Lines changed: 135 additions & 34 deletions

File tree

source/core/types/ut_suite_item.tps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ create or replace type ut_suite_item force under ut_event_item (
3636
/**
3737
* Full path of the invocation of the item (including the items name itself)
3838
*/
39-
path varchar2(4000 byte),
39+
path varchar2(1000 byte),
4040
/**
4141
* The type of the rollback behavior
4242
*/

source/core/ut_suite_manager.pkb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ create or replace package body ut_suite_manager is
1616
limitations under the License.
1717
*/
1818

19+
gc_suitpath_error_message constant varchar2(100) := 'Suitepath exceeds 1000 CHAR on: ';
1920

2021
type t_path_item is record (
2122
object_name varchar2(250),
@@ -477,12 +478,21 @@ create or replace package body ut_suite_manager is
477478
) is
478479
l_annotated_objects ut_annotated_objects;
479480
l_suite_items ut_suite_items;
481+
482+
l_bad_suitepath_obj ut_varchar2_list := ut_varchar2_list();
483+
ex_string_too_small exception;
484+
pragma exception_init (ex_string_too_small,-06502);
480485
begin
481486
loop
482487
fetch a_annotated_objects bulk collect into l_annotated_objects limit 10;
483488

484489
for i in 1 .. l_annotated_objects.count loop
485-
ut_suite_builder.create_suite_item_list( l_annotated_objects( i ), l_suite_items );
490+
begin
491+
ut_suite_builder.create_suite_item_list( l_annotated_objects( i ), l_suite_items );
492+
exception
493+
when ex_string_too_small then
494+
ut_utils.append_to_list(l_bad_suitepath_obj,a_owner_name||'.'||l_annotated_objects( i ).object_name);
495+
end;
486496
ut_suite_cache_manager.save_object_cache(
487497
a_owner_name,
488498
l_annotated_objects( i ).object_name,
@@ -493,7 +503,14 @@ create or replace package body ut_suite_manager is
493503
exit when a_annotated_objects%notfound;
494504
end loop;
495505
close a_annotated_objects;
496-
506+
507+
--Check for any invalid suitepath objects
508+
if l_bad_suitepath_obj.count > 0 then
509+
raise_application_error(
510+
ut_utils.gc_value_too_large,
511+
ut_utils.to_string(gc_suitpath_error_message||ut_utils.table_to_clob(l_bad_suitepath_obj,','))
512+
);
513+
end if;
497514
end;
498515

499516
procedure refresh_cache(

source/core/ut_utils.pkb

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,48 +77,66 @@ create or replace package body ut_utils is
7777
$end
7878
end;
7979

80-
function to_string(a_value varchar2, a_qoute_char varchar2 := '''') return varchar2 is
81-
l_len integer := coalesce(length(a_value),0);
82-
l_result varchar2(32767);
83-
begin
84-
if l_len = 0 then
80+
function to_string(
81+
a_value varchar2,
82+
a_quote_char varchar2 := '''',
83+
a_max_output_len in number := gc_max_output_string_length
84+
) return varchar2 is
85+
l_result varchar2(32767);
86+
c_length constant integer := coalesce( length( a_value ), 0 );
87+
c_max_input_string_length constant integer := a_max_output_len - coalesce( length( a_quote_char ) * 2, 0 );
88+
c_overflow_substr_len constant integer := c_max_input_string_length - gc_more_data_string_len;
89+
begin
90+
if c_length = 0 then
8591
l_result := gc_null_string;
86-
elsif l_len <= gc_max_input_string_length then
87-
l_result := surround_with(a_value, a_qoute_char);
92+
elsif c_length <= c_max_input_string_length then
93+
l_result := surround_with(a_value, a_quote_char);
8894
else
89-
l_result := surround_with(substr(a_value,1,gc_overflow_substr_len),a_qoute_char) || gc_more_data_string;
95+
l_result := surround_with(substr(a_value, 1, c_overflow_substr_len ), a_quote_char) || gc_more_data_string;
9096
end if ;
9197
return l_result;
9298
end;
9399

94-
function to_string(a_value clob, a_qoute_char varchar2 := '''') return varchar2 is
95-
l_len integer := coalesce(dbms_lob.getlength(a_value), 0);
96-
l_result varchar2(32767);
100+
function to_string(
101+
a_value clob,
102+
a_quote_char varchar2 := '''',
103+
a_max_output_len in number := gc_max_output_string_length
104+
) return varchar2 is
105+
l_result varchar2(32767);
106+
c_length constant integer := coalesce(dbms_lob.getlength(a_value), 0);
107+
c_max_input_string_length constant integer := a_max_output_len - coalesce( length( a_quote_char ) * 2, 0 );
108+
c_overflow_substr_len constant integer := c_max_input_string_length - gc_more_data_string_len;
97109
begin
98110
if a_value is null then
99111
l_result := gc_null_string;
100-
elsif l_len = 0 then
112+
elsif c_length = 0 then
101113
l_result := gc_empty_string;
102-
elsif l_len <= gc_max_input_string_length then
103-
l_result := surround_with(a_value,a_qoute_char);
114+
elsif c_length <= c_max_input_string_length then
115+
l_result := surround_with(a_value,a_quote_char);
104116
else
105-
l_result := surround_with(dbms_lob.substr(a_value, gc_overflow_substr_len),a_qoute_char) || gc_more_data_string;
117+
l_result := surround_with(dbms_lob.substr(a_value, c_overflow_substr_len), a_quote_char) || gc_more_data_string;
106118
end if;
107119
return l_result;
108120
end;
109121

110-
function to_string(a_value blob, a_qoute_char varchar2 := '''') return varchar2 is
111-
l_len integer := coalesce(dbms_lob.getlength(a_value), 0);
112-
l_result varchar2(32767);
122+
function to_string(
123+
a_value blob,
124+
a_quote_char varchar2 := '''',
125+
a_max_output_len in number := gc_max_output_string_length
126+
) return varchar2 is
127+
l_result varchar2(32767);
128+
c_length constant integer := coalesce(dbms_lob.getlength(a_value), 0);
129+
c_max_input_string_length constant integer := a_max_output_len - coalesce( length( a_quote_char ) * 2, 0 );
130+
c_overflow_substr_len constant integer := c_max_input_string_length - gc_more_data_string_len;
113131
begin
114132
if a_value is null then
115133
l_result := gc_null_string;
116-
elsif l_len = 0 then
134+
elsif c_length = 0 then
117135
l_result := gc_empty_string;
118-
elsif l_len <= gc_max_input_string_length then
119-
l_result := surround_with(rawtohex(a_value),a_qoute_char);
136+
elsif c_length <= c_max_input_string_length then
137+
l_result := surround_with(rawtohex(a_value),a_quote_char);
120138
else
121-
l_result := to_string( rawtohex(dbms_lob.substr(a_value, gc_overflow_substr_len)) );
139+
l_result := to_string( rawtohex(dbms_lob.substr(a_value, c_overflow_substr_len)) );
122140
end if ;
123141
return l_result;
124142
end;

source/core/ut_utils.pks

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,17 @@ create or replace package ut_utils authid definer is
102102
pragma exception_init (ex_failure_for_all, -24381);
103103

104104
ex_dml_for_all exception;
105-
gc_dml_for_all constant pls_integer := -20215;
106-
pragma exception_init (ex_dml_for_all, -20215);
105+
gc_dml_for_all constant pls_integer := -20216;
106+
pragma exception_init (ex_dml_for_all, -20216);
107+
108+
ex_value_too_large exception;
109+
gc_value_too_large constant pls_integer := -20217;
110+
pragma exception_init (ex_value_too_large, -20217);
107111

108112
gc_max_storage_varchar2_len constant integer := 4000;
109113
gc_max_output_string_length constant integer := 4000;
110-
gc_max_input_string_length constant integer := gc_max_output_string_length - 2; --we need to remove 2 chars for quotes around string
111114
gc_more_data_string constant varchar2(5) := '[...]';
112-
gc_overflow_substr_len constant integer := gc_max_input_string_length - length(gc_more_data_string);
115+
gc_more_data_string_len constant integer := length( gc_more_data_string );
113116
gc_number_format constant varchar2(100) := 'TM9';
114117
gc_date_format constant varchar2(100) := 'yyyy-mm-dd"T"hh24:mi:ss';
115118
gc_timestamp_format constant varchar2(100) := 'yyyy-mm-dd"T"hh24:mi:ssxff';
@@ -151,11 +154,23 @@ create or replace package ut_utils authid definer is
151154

152155
procedure debug_log(a_message clob);
153156

154-
function to_string(a_value varchar2, a_qoute_char varchar2 := '''') return varchar2;
155-
156-
function to_string(a_value clob, a_qoute_char varchar2 := '''') return varchar2;
157-
158-
function to_string(a_value blob, a_qoute_char varchar2 := '''') return varchar2;
157+
function to_string(
158+
a_value varchar2,
159+
a_quote_char varchar2 := '''',
160+
a_max_output_len in number := gc_max_output_string_length
161+
) return varchar2;
162+
163+
function to_string(
164+
a_value clob,
165+
a_quote_char varchar2 := '''',
166+
a_max_output_len in number := gc_max_output_string_length
167+
) return varchar2;
168+
169+
function to_string(
170+
a_value blob,
171+
a_quote_char varchar2 := '''',
172+
a_max_output_len in number := gc_max_output_string_length
173+
) return varchar2;
159174

160175
function to_string(a_value boolean) return varchar2;
161176

test/core/test_suite_manager.pkb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@ create or replace package body test_suite_manager is
33
ex_obj_doesnt_exist exception;
44
pragma exception_init(ex_obj_doesnt_exist, -04043);
55

6+
procedure create_dummy_long_test_package is
7+
pragma autonomous_transaction;
8+
begin
9+
execute immediate q'[create or replace package ut3.dummy_long_test_package as
10+
11+
--%suitepath(verylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtext)
12+
--%suite(dummy_test_suite)
13+
14+
--%test(dummy_test)
15+
procedure some_dummy_test_procedure;
16+
end;]';
17+
18+
execute immediate q'[create or replace package ut3.dummy_long_test_package1 as
19+
20+
--%suitepath(verylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtextverylongtext)
21+
--%suite(dummy_test_suite1)
22+
23+
--%test(dummy_test)
24+
procedure some_dummy_test_procedure;
25+
end;]';
26+
end;
27+
28+
procedure drop_dummy_long_test_package is
29+
pragma autonomous_transaction;
30+
begin
31+
execute immediate q'[drop package ut3.dummy_long_test_package]';
32+
execute immediate q'[drop package ut3.dummy_long_test_package1]';
33+
end;
34+
635
procedure compile_dummy_packages is
736
pragma autonomous_transaction;
837
begin
@@ -1451,5 +1480,18 @@ end;]';
14511480
execute immediate q'[drop package ut3.some_test_package]';
14521481
end;
14531482

1483+
procedure add_new_long_test_package is
1484+
l_actual ut3.ut_object_names;
1485+
l_expected_message varchar2(500);
1486+
begin
1487+
l_expected_message := q'[ORA-20217: 'Suitepath exceeds 1000 CHAR on: UT3.DUMMY_LONG_TEST_PACKAGE,UT3.DUMMY_LONG_TEST_PACKAGE1'%]';
1488+
l_actual := ut3.ut_suite_manager.get_schema_ut_packages(ut3.ut_varchar2_rows('UT3'));
1489+
ut.fail('Expected exception for suitpaths over 1k for two packages');
1490+
exception
1491+
when others then
1492+
ut.expect(dbms_utility.format_error_stack()).to_be_like(l_expected_message);
1493+
ut.expect(SQLCODE).to_equal(ut3.ut_utils.gc_value_too_large);
1494+
end;
1495+
14541496
end test_suite_manager;
14551497
/

test/core/test_suite_manager.pks

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ create or replace package test_suite_manager is
33
--%suite(suite_manager)
44
--%suitepath(utplsql.core)
55

6+
procedure create_dummy_long_test_package;
7+
8+
procedure drop_dummy_long_test_package;
9+
610
--%beforeall
711
procedure compile_dummy_packages;
812
--%afterall
@@ -162,5 +166,10 @@ create or replace package test_suite_manager is
162166

163167
--%endcontext
164168

169+
--%test(Adds suitepath to cache over 1k characters long)
170+
--%beforetest(create_dummy_long_test_package)
171+
--%aftertest(drop_dummy_long_test_package)
172+
procedure add_new_long_test_package;
173+
165174
end test_suite_manager;
166175
/

0 commit comments

Comments
 (0)