Fix hardcoded owner

This commit is contained in:
Jan Kvetina 2022-01-15 09:02:11 +01:00
parent eb8499239a
commit 2fbe88c62a
4 changed files with 31 additions and 2 deletions

View File

@ -233,6 +233,16 @@ CREATE OR REPLACE PACKAGE app AS
--
-- Return current owner (because APEX dont like using USER)
--
FUNCTION get_owner (
in_app_id apps.app_id%TYPE := NULL
)
RETURN apex_applications.owner%TYPE;

View File

@ -274,6 +274,25 @@ CREATE OR REPLACE PACKAGE BODY app AS
FUNCTION get_owner (
in_app_id apps.app_id%TYPE := NULL
)
RETURN apex_applications.owner%TYPE
AS
out_owner apex_applications.owner%TYPE;
BEGIN
SELECT a.owner INTO out_owner
FROM apex_applications a
WHERE a.application_id = COALESCE(in_app_id, app.get_app_id());
--
RETURN out_owner;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN app.schema_owner;
END;
PROCEDURE create_session
AS
PRAGMA AUTONOMOUS_TRANSACTION;

View File

@ -19,7 +19,7 @@ FROM (
LEVEL AS level_
FROM user_dependencies d
CROSS JOIN x
WHERE d.referenced_owner = 'CORE' -- @TODO: hardcoded user
WHERE d.referenced_owner = app.get_owner()
CONNECT BY NOCYCLE PRIOR d.name = d.referenced_name
AND LEVEL <= 3 -- limit depth
START WITH d.referenced_name = x.table_name

View File

@ -31,7 +31,7 @@ WHERE r.query_type_code = 'TABLE'
SELECT DISTINCT d.name AS view_name
FROM user_dependencies d
CROSS JOIN x
WHERE d.referenced_owner = 'CORE' -- @TODO: hardcoded schema
WHERE d.referenced_owner = app.get_owner()
AND d.type = 'VIEW'
CONNECT BY NOCYCLE d.referenced_name = PRIOR d.name
AND d.referenced_type = 'VIEW'