cleanup code

This commit is contained in:
ogobrecht 2019-06-15 21:36:08 +02:00
parent eb81b8135a
commit 190bcb67ec
4 changed files with 688 additions and 1046 deletions

1550
PLEX.pkb

File diff suppressed because it is too large Load Diff

101
PLEX.pks
View File

@ -59,8 +59,7 @@ CHANGELOG
-- CONSTANTS, TYPES -- CONSTANTS, TYPES
-------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------
c_app_info_length CONSTANT PLS_INTEGER := 64; c_app_info_length CONSTANT PLS_INTEGER := 64;
SUBTYPE app_info_text IS VARCHAR2(64 CHAR); SUBTYPE app_info_text IS VARCHAR2(64 CHAR);
TYPE rec_error_log IS RECORD ( TYPE rec_error_log IS RECORD (
@ -69,7 +68,6 @@ TYPE rec_error_log IS RECORD (
error_text VARCHAR2(200), error_text VARCHAR2(200),
call_stack VARCHAR2(500) call_stack VARCHAR2(500)
); );
TYPE tab_error_log IS TABLE OF rec_error_log; TYPE tab_error_log IS TABLE OF rec_error_log;
TYPE rec_runtime_log IS RECORD ( TYPE rec_runtime_log IS RECORD (
@ -81,14 +79,12 @@ TYPE rec_runtime_log IS RECORD (
module app_info_text, module app_info_text,
action app_info_text action app_info_text
); );
TYPE tab_runtime_log IS TABLE OF rec_runtime_log; TYPE tab_runtime_log IS TABLE OF rec_runtime_log;
TYPE rec_export_file IS RECORD ( TYPE rec_export_file IS RECORD (
name VARCHAR2(255), name VARCHAR2(255),
contents CLOB contents CLOB
); );
TYPE tab_export_files IS TABLE OF rec_export_file; TYPE tab_export_files IS TABLE OF rec_export_file;
TYPE tab_varchar2 IS TABLE OF varchar2(32767); TYPE tab_varchar2 IS TABLE OF varchar2(32767);
@ -152,21 +148,16 @@ BEGIN
l_file_collection := plex.backapp( l_file_collection := plex.backapp(
p_app_id => 100, -- parameter only available when APEX installed p_app_id => 100, -- parameter only available when APEX installed
p_include_object_ddl => false, p_include_object_ddl => false,
p_include_data => false p_include_data => false);
);
-- do something with the file collection -- do something with the file collection
FOR i IN 1..l_file_collection.count LOOP FOR i IN 1..l_file_collection.count LOOP
dbms_output.put_line( dbms_output.put_line(i || ' | '
i || lpad(round(length(l_file_collection(i).contents) / 1024), 3) || ' kB' || ' | '
|| ' | ' || l_file_collection(i).name);
|| lpad(round(length(l_file_collection(i).contents) / 1024), 3) || ' kB'
|| ' | '
|| l_file_collection(i).name
);
END LOOP; END LOOP;
END; END;
{{SLASH}} {{/}}
``` ```
EXAMPLE ZIP FILE PL/SQL EXAMPLE ZIP FILE PL/SQL
@ -178,13 +169,12 @@ BEGIN
l_zip_file := plex.to_zip(plex.backapp( l_zip_file := plex.to_zip(plex.backapp(
p_app_id => 100, -- parameter only available when APEX installed p_app_id => 100, -- parameter only available when APEX installed
p_include_object_ddl => true, p_include_object_ddl => true,
p_include_data => false p_include_data => false));
));
-- do something with the zip file -- do something with the zip file
-- Your code here... -- Your code here...
END; END;
{{SLASH}} {{/}}
``` ```
EXAMPLE ZIP FILE SQL EXAMPLE ZIP FILE SQL
@ -229,20 +219,19 @@ WITH
p_include_error_log => true, p_include_error_log => true,
p_base_path_backend => 'app_backend', p_base_path_backend => 'app_backend',
p_base_path_frontend => 'app_frontend', p_base_path_frontend => 'app_frontend',
p_base_path_data => 'app_data' p_base_path_data => 'app_data'));
));
END backapp; END backapp;
SELECT backapp FROM dual; SELECT backapp FROM dual;
{{SLASH}} {{/}}
``` ```
**/ **/
PROCEDURE add_query ( PROCEDURE add_query (
p_query IN VARCHAR2, -- The query itself p_query IN VARCHAR2, -- The query itself
p_file_name IN VARCHAR2, -- File name like 'Path/to/your/file-without-extension'. p_file_name IN VARCHAR2, -- File name like 'Path/to/your/file-without-extension'.
p_max_rows IN NUMBER DEFAULT 1000 -- The maximum number of rows to be included in your file. p_max_rows IN NUMBER DEFAULT 1000 -- The maximum number of rows to be included in your file.
); );
/** /**
Add a query to be processed by the method queries_to_csv. You can add as many queries as you like. Add a query to be processed by the method queries_to_csv. You can add as many queries as you like.
@ -253,10 +242,9 @@ EXAMPLE
BEGIN BEGIN
plex.add_query( plex.add_query(
p_query => 'select * from user_tables', p_query => 'select * from user_tables',
p_file_name => 'user_tables' p_file_name => 'user_tables');
);
END; END;
{{SLASH}} {{/}}
``` ```
**/ **/
@ -282,29 +270,23 @@ BEGIN
--fill the queries array --fill the queries array
plex.add_query( plex.add_query(
p_query => 'select * from user_tables', p_query => 'select * from user_tables',
p_file_name => 'user_tables' p_file_name => 'user_tables');
);
plex.add_query( plex.add_query(
p_query => 'select * from user_tab_columns', p_query => 'select * from user_tab_columns',
p_file_name => 'user_tab_columns', p_file_name => 'user_tab_columns',
p_max_rows => 10000 p_max_rows => 10000);
);
-- process the queries -- process the queries
l_file_collection := plex.queries_to_csv; l_file_collection := plex.queries_to_csv;
-- do something with the file collection -- do something with the file collection
FOR i IN 1..l_file_collection.count LOOP FOR i IN 1..l_file_collection.count LOOP
dbms_output.put_line( dbms_output.put_line(i || ' | '
i || lpad(round(length(l_file_collection(i).contents) / 1024), 3) || ' kB' || ' | '
|| ' | ' || l_file_collection(i).name);
|| lpad(round(length(l_file_collection(i).contents) / 1024), 3) || ' kB'
|| ' | '
|| l_file_collection(i).name
);
END LOOP; END LOOP;
END; END;
{{SLASH}} {{/}}
``` ```
EXPORT EXPORT ZIP FILE PL/SQL EXPORT EXPORT ZIP FILE PL/SQL
@ -317,13 +299,11 @@ BEGIN
--fill the queries array --fill the queries array
plex.add_query( plex.add_query(
p_query => 'select * from user_tables', p_query => 'select * from user_tables',
p_file_name => 'user_tables' p_file_name => 'user_tables');
);
plex.add_query( plex.add_query(
p_query => 'select * from user_tab_columns', p_query => 'select * from user_tab_columns',
p_file_name => 'user_tab_columns', p_file_name => 'user_tab_columns',
p_max_rows => 10000 p_max_rows => 10000);
);
-- process the queries -- process the queries
l_zip_file := plex.to_zip(plex.queries_to_csv); l_zip_file := plex.to_zip(plex.queries_to_csv);
@ -331,7 +311,7 @@ BEGIN
-- do something with the zip file -- do something with the zip file
-- Your code here... -- Your code here...
END; END;
{{SLASH}} {{/}}
``` ```
EXAMPLE EXPORT ZIP FILE SQL EXAMPLE EXPORT ZIP FILE SQL
@ -343,18 +323,16 @@ WITH
BEGIN BEGIN
plex.add_query( plex.add_query(
p_query => 'select * from user_tables', p_query => 'select * from user_tables',
p_file_name => 'user_tables' p_file_name => 'user_tables');
);
plex.add_query( plex.add_query(
p_query => 'select * from user_tab_columns', p_query => 'select * from user_tab_columns',
p_file_name => 'user_tab_columns', p_file_name => 'user_tab_columns',
p_max_rows => 10000 p_max_rows => 10000);
);
v_return := plex.to_zip(plex.queries_to_csv); v_return := plex.to_zip(plex.queries_to_csv);
RETURN v_return; RETURN v_return;
END queries_to_csv_zip; END queries_to_csv_zip;
SELECT queries_to_csv_zip FROM dual; SELECT queries_to_csv_zip FROM dual;
{{SLASH}} {{/}}
**/ **/
@ -373,8 +351,7 @@ DECLARE
BEGIN BEGIN
l_zip := plex.to_zip(plex.backapp( l_zip := plex.to_zip(plex.backapp(
p_app_id => 100, p_app_id => 100,
p_include_object_ddl => true p_include_object_ddl => true));
));
-- do something with the zip file... -- do something with the zip file...
END; END;
@ -446,29 +423,19 @@ FUNCTION util_zip_blob_to_num (
p_len IN INTEGER, p_len IN INTEGER,
p_pos IN INTEGER p_pos IN INTEGER
) RETURN NUMBER; ) RETURN NUMBER;
FUNCTION util_zip_little_endian ( FUNCTION util_zip_little_endian (
p_big IN NUMBER, p_big IN NUMBER,
p_bytes IN PLS_INTEGER := 4 p_bytes IN PLS_INTEGER := 4
) RETURN RAW; ) RETURN RAW;
PROCEDURE util_zip_add_file ( PROCEDURE util_zip_add_file (
p_zipped_blob IN OUT BLOB, p_zipped_blob IN OUT BLOB,
p_name IN VARCHAR2, p_name IN VARCHAR2,
p_content IN BLOB p_content IN BLOB
); );
PROCEDURE util_zip_finish ( PROCEDURE util_zip_finish (
p_zipped_blob IN OUT BLOB p_zipped_blob IN OUT BLOB
); );
/* FIXME: implement this
FUNCTION util_multireplace (
p_source_string IN VARCHAR2,
p_replacements IN tab_varchar2
) RETURN VARCHAR2;
*/
FUNCTION util_multi_replace ( FUNCTION util_multi_replace (
p_source_string VARCHAR2, p_source_string VARCHAR2,
p_01_find VARCHAR2 DEFAULT NULL, p_01_replace VARCHAR2 DEFAULT NULL, p_01_find VARCHAR2 DEFAULT NULL, p_01_replace VARCHAR2 DEFAULT NULL,
@ -506,7 +473,9 @@ PROCEDURE util_setup_dbms_metadata (
p_emit_schema IN BOOLEAN DEFAULT false p_emit_schema IN BOOLEAN DEFAULT false
); );
PROCEDURE util_ensure_unique_file_names; PROCEDURE util_ensure_unique_file_names (
p_export_files IN OUT tab_export_files
);
-------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------
-- The following tools are working on global private package variables -- The following tools are working on global private package variables
@ -556,9 +525,13 @@ PROCEDURE util_clob_query_to_csv (
p_header_prefix IN VARCHAR2 DEFAULT NULL p_header_prefix IN VARCHAR2 DEFAULT NULL
); );
PROCEDURE util_clob_create_error_log (p_export_files IN OUT NOCOPY tab_export_files); PROCEDURE util_clob_create_error_log (
p_export_files IN OUT NOCOPY tab_export_files
);
PROCEDURE util_clob_create_runtime_log (p_export_files IN OUT NOCOPY tab_export_files); PROCEDURE util_clob_create_runtime_log (
p_export_files IN OUT NOCOPY tab_export_files
);
$end $end

View File

@ -92,21 +92,16 @@ BEGIN
l_file_collection := plex.backapp( l_file_collection := plex.backapp(
p_app_id => 100, -- parameter only available when APEX installed p_app_id => 100, -- parameter only available when APEX installed
p_include_object_ddl => false, p_include_object_ddl => false,
p_include_data => false p_include_data => false);
);
-- do something with the file collection -- do something with the file collection
FOR i IN 1..l_file_collection.count LOOP FOR i IN 1..l_file_collection.count LOOP
dbms_output.put_line( dbms_output.put_line(i || ' | '
i || lpad(round(length(l_file_collection(i).contents) / 1024), 3) || ' kB' || ' | '
|| ' | ' || l_file_collection(i).name);
|| lpad(round(length(l_file_collection(i).contents) / 1024), 3) || ' kB'
|| ' | '
|| l_file_collection(i).name
);
END LOOP; END LOOP;
END; END;
{{SLASH}} {{/}}
``` ```
EXAMPLE ZIP FILE PL/SQL EXAMPLE ZIP FILE PL/SQL
@ -118,13 +113,12 @@ BEGIN
l_zip_file := plex.to_zip(plex.backapp( l_zip_file := plex.to_zip(plex.backapp(
p_app_id => 100, -- parameter only available when APEX installed p_app_id => 100, -- parameter only available when APEX installed
p_include_object_ddl => true, p_include_object_ddl => true,
p_include_data => false p_include_data => false));
));
-- do something with the zip file -- do something with the zip file
-- Your code here... -- Your code here...
END; END;
{{SLASH}} {{/}}
``` ```
EXAMPLE ZIP FILE SQL EXAMPLE ZIP FILE SQL
@ -169,11 +163,10 @@ WITH
p_include_error_log => true, p_include_error_log => true,
p_base_path_backend => 'app_backend', p_base_path_backend => 'app_backend',
p_base_path_frontend => 'app_frontend', p_base_path_frontend => 'app_frontend',
p_base_path_data => 'app_data' p_base_path_data => 'app_data'));
));
END backapp; END backapp;
SELECT backapp FROM dual; SELECT backapp FROM dual;
{{SLASH}} {{/}}
``` ```
SIGNATURE SIGNATURE
@ -230,19 +223,18 @@ EXAMPLE
BEGIN BEGIN
plex.add_query( plex.add_query(
p_query => 'select * from user_tables', p_query => 'select * from user_tables',
p_file_name => 'user_tables' p_file_name => 'user_tables');
);
END; END;
{{SLASH}} {{/}}
``` ```
SIGNATURE SIGNATURE
```sql ```sql
PROCEDURE add_query ( PROCEDURE add_query (
p_query IN VARCHAR2, -- The query itself p_query IN VARCHAR2, -- The query itself
p_file_name IN VARCHAR2, -- File name like 'Path/to/your/file-without-extension'. p_file_name IN VARCHAR2, -- File name like 'Path/to/your/file-without-extension'.
p_max_rows IN NUMBER DEFAULT 1000 -- The maximum number of rows to be included in your file. p_max_rows IN NUMBER DEFAULT 1000 -- The maximum number of rows to be included in your file.
); );
``` ```
@ -262,29 +254,23 @@ BEGIN
--fill the queries array --fill the queries array
plex.add_query( plex.add_query(
p_query => 'select * from user_tables', p_query => 'select * from user_tables',
p_file_name => 'user_tables' p_file_name => 'user_tables');
);
plex.add_query( plex.add_query(
p_query => 'select * from user_tab_columns', p_query => 'select * from user_tab_columns',
p_file_name => 'user_tab_columns', p_file_name => 'user_tab_columns',
p_max_rows => 10000 p_max_rows => 10000);
);
-- process the queries -- process the queries
l_file_collection := plex.queries_to_csv; l_file_collection := plex.queries_to_csv;
-- do something with the file collection -- do something with the file collection
FOR i IN 1..l_file_collection.count LOOP FOR i IN 1..l_file_collection.count LOOP
dbms_output.put_line( dbms_output.put_line(i || ' | '
i || lpad(round(length(l_file_collection(i).contents) / 1024), 3) || ' kB' || ' | '
|| ' | ' || l_file_collection(i).name);
|| lpad(round(length(l_file_collection(i).contents) / 1024), 3) || ' kB'
|| ' | '
|| l_file_collection(i).name
);
END LOOP; END LOOP;
END; END;
{{SLASH}} {{/}}
``` ```
EXPORT EXPORT ZIP FILE PL/SQL EXPORT EXPORT ZIP FILE PL/SQL
@ -297,13 +283,11 @@ BEGIN
--fill the queries array --fill the queries array
plex.add_query( plex.add_query(
p_query => 'select * from user_tables', p_query => 'select * from user_tables',
p_file_name => 'user_tables' p_file_name => 'user_tables');
);
plex.add_query( plex.add_query(
p_query => 'select * from user_tab_columns', p_query => 'select * from user_tab_columns',
p_file_name => 'user_tab_columns', p_file_name => 'user_tab_columns',
p_max_rows => 10000 p_max_rows => 10000);
);
-- process the queries -- process the queries
l_zip_file := plex.to_zip(plex.queries_to_csv); l_zip_file := plex.to_zip(plex.queries_to_csv);
@ -311,7 +295,7 @@ BEGIN
-- do something with the zip file -- do something with the zip file
-- Your code here... -- Your code here...
END; END;
{{SLASH}} {{/}}
``` ```
EXAMPLE EXPORT ZIP FILE SQL EXAMPLE EXPORT ZIP FILE SQL
@ -323,18 +307,16 @@ WITH
BEGIN BEGIN
plex.add_query( plex.add_query(
p_query => 'select * from user_tables', p_query => 'select * from user_tables',
p_file_name => 'user_tables' p_file_name => 'user_tables');
);
plex.add_query( plex.add_query(
p_query => 'select * from user_tab_columns', p_query => 'select * from user_tab_columns',
p_file_name => 'user_tab_columns', p_file_name => 'user_tab_columns',
p_max_rows => 10000 p_max_rows => 10000);
);
v_return := plex.to_zip(plex.queries_to_csv); v_return := plex.to_zip(plex.queries_to_csv);
RETURN v_return; RETURN v_return;
END queries_to_csv_zip; END queries_to_csv_zip;
SELECT queries_to_csv_zip FROM dual; SELECT queries_to_csv_zip FROM dual;
{{SLASH}} {{/}}
SIGNATURE SIGNATURE
@ -362,8 +344,7 @@ DECLARE
BEGIN BEGIN
l_zip := plex.to_zip(plex.backapp( l_zip := plex.to_zip(plex.backapp(
p_app_id => 100, p_app_id => 100,
p_include_object_ddl => true p_include_object_ddl => true));
));
-- do something with the zip file... -- do something with the zip file...
END; END;

View File

@ -5,10 +5,10 @@ prompt Installing PL/SQL Export Utilities
prompt ================================== prompt ==================================
prompt Set compiler flags prompt Set compiler flags
DECLARE DECLARE
v_apex_installed VARCHAR2(5) := 'FALSE'; -- Do not change (is set dynamically). v_apex_installed VARCHAR2(5) := 'FALSE'; -- Do not change (is set dynamically).
v_ords_installed VARCHAR2(5) := 'FALSE'; -- Do not change (is set dynamically). v_ords_installed VARCHAR2(5) := 'FALSE'; -- Do not change (is set dynamically).
v_utils_public VARCHAR2(5) := 'FALSE'; -- Make utilities public available (for testing or other usages). v_utils_public VARCHAR2(5) := 'FALSE'; -- Make utilities public available (for testing or other usages).
v_debug_on VARCHAR2(5) := 'TRUE'; -- Object DDL: extract only one object per type to find problematic ones and save time in big schemas like APEX_XXX. v_debug_on VARCHAR2(5) := 'FALSE'; -- Object DDL: extract only one object per type to find problematic ones and save time in big schemas like APEX_XXX.
BEGIN BEGIN
FOR i IN ( FOR i IN (
SELECT * SELECT *