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

Skip to content
Merged
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
Adding cache for source lines (if exceptions found)
  • Loading branch information
jgebal committed Aug 1, 2017
commit 0213cdcf9c85ee739344c9b43f5edaae5f5fa7d3
34 changes: 23 additions & 11 deletions source/core/ut_metadata.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ create or replace package body ut_metadata as
limitations under the License.
*/

type t_cache is table of all_source.text%type;
g_source_cache t_cache;
g_cached_object varchar2(500);
------------------------------
--public definitions

Expand Down Expand Up @@ -130,20 +133,29 @@ create or replace package body ut_metadata as
end;

function get_source_definition_line(a_owner varchar2, a_object_name varchar2, a_line_no integer) return varchar2 is
l_line varchar2(4000);
l_cursor sys_refcursor;
l_view_name varchar2(128) := get_dba_view('dba_source');
l_line all_source.text%type;
c_key constant varchar2(500) := a_owner || '.' || a_object_name;
begin
open l_cursor for 'select text from '||l_view_name||q'[ s
where s.owner = :a_owner and s.name = :a_object_name and s.line = :a_line_no
-- skip the declarations, consider only definitions
and s.type not in ('PACKAGE','TYPE')]' using a_owner, a_object_name, a_line_no;
fetch l_cursor into l_line;
close l_cursor;
return ltrim(rtrim( l_line, chr(10) ));
exception
when no_data_found then
return null;
if not nvl(c_key = g_cached_object, false) then
g_cached_object := c_key;
execute immediate
'select trim(text) text
from '||l_view_name||q'[ s
where s.owner = :a_owner
and s.name = :a_object_name
/*skip the declarations, consider only definitions*/
and s.type not in ('PACKAGE', 'TYPE')
order by line]'
bulk collect into g_source_cache
using a_owner, a_object_name;
end if;

if g_source_cache.exists(a_line_no) then
l_line := g_source_cache(a_line_no);
end if;
return l_line;
end;

function get_dba_view(a_view_name varchar2) return varchar2 is
Expand Down