added comments for set_file_association function
git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@3257 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
@@ -21,39 +21,51 @@ PROCEDURE export_table_to_csv(p_table IN VARCHAR2,
|
|||||||
end MIP_FILES;
|
end MIP_FILES;
|
||||||
/
|
/
|
||||||
create or replace package body MIP_FILES as
|
create or replace package body MIP_FILES as
|
||||||
|
/*
|
||||||
function set_file_association(p_uri in varchar2,
|
FUNCTION set_file_association
|
||||||
p_description in varchar2,
|
- sets the association between a object within webmip to a file held in the
|
||||||
p_docu_type in varchar2,
|
- APEX application files view.
|
||||||
p_rt_code in varchar2,
|
%param p_uri - the uri of the file (the contents of the name column in APEX application files)
|
||||||
p_qute_id in number,
|
%param p_description - description of the file, will be set in documents and document_roles table
|
||||||
p_enqu_id in number,
|
%param p_docu_type - INDO (held within webmip db), EXDO (held outside webmip), FIDO (on file system)
|
||||||
p_drwg_code in varchar2,
|
%param p_rt_code - type of role for docment eg 'ENQUIRY SUPPORTING DOC' see role types table
|
||||||
p_doro_type in varchar2) return boolean is
|
%param p_qute_id - the quote id if applicable otherwise supply null
|
||||||
l_doc_id number;
|
%param p_enqu_id - the enquiry id if applicable otherwise supply null
|
||||||
|
%param p_drwg_code - the drawing code if applicable otherwise supply null
|
||||||
begin
|
%param p_doro_type - DRRO (for a drawing), ENDO (for an enquiry), QUDO (for a quote)
|
||||||
--reference it in the documents table
|
*/
|
||||||
insert into documents( uri, description, id, docu_type )
|
function set_file_association(p_uri in varchar2,
|
||||||
values (p_uri,
|
p_description in varchar2,
|
||||||
p_description,
|
p_docu_type in varchar2,
|
||||||
docu_seq.NEXTVAL,
|
p_rt_code in varchar2,
|
||||||
p_docu_type)
|
p_qute_id in number,
|
||||||
returning id into l_doc_id;
|
p_enqu_id in number,
|
||||||
--set up a role for the document
|
p_drwg_code in varchar2,
|
||||||
insert into document_roles(rt_code, start_date,description,qute_id,enqu_id,drwg_code,id,doro_type,docu_id)
|
p_doro_type in varchar2) return boolean is
|
||||||
values (p_rt_code,
|
l_doc_id number;
|
||||||
sysdate,
|
|
||||||
p_description,
|
begin
|
||||||
p_qute_id,
|
--reference it in the documents table
|
||||||
p_enqu_id,
|
insert into documents( uri, description, id, docu_type )
|
||||||
p_drwg_code,
|
values (p_uri,
|
||||||
doro_seq.NEXTVAL,
|
p_description,
|
||||||
p_doro_type,
|
docu_seq.NEXTVAL,
|
||||||
l_doc_id);
|
p_docu_type)
|
||||||
--if it works then return true
|
returning id into l_doc_id;
|
||||||
return true;
|
--set up a role for the document
|
||||||
end set_file_association;
|
insert into document_roles(rt_code, start_date,description,qute_id,enqu_id,drwg_code,id,doro_type,docu_id)
|
||||||
|
values (p_rt_code,
|
||||||
|
sysdate,
|
||||||
|
p_description,
|
||||||
|
p_qute_id,
|
||||||
|
p_enqu_id,
|
||||||
|
p_drwg_code,
|
||||||
|
doro_seq.NEXTVAL,
|
||||||
|
p_doro_type,
|
||||||
|
l_doc_id);
|
||||||
|
--if it works then return true
|
||||||
|
return true;
|
||||||
|
end set_file_association;
|
||||||
/*
|
/*
|
||||||
PROCEDURE export_data_to_csv
|
PROCEDURE export_data_to_csv
|
||||||
- allows an admin user to create a CSV export of a table in webMIP.
|
- allows an admin user to create a CSV export of a table in webMIP.
|
||||||
@@ -63,87 +75,87 @@ end set_file_association;
|
|||||||
%param p_column_headers - tables column names be exported as a header
|
%param p_column_headers - tables column names be exported as a header
|
||||||
%param p_delimiter - what is the delimiter value is for each field (default ',')
|
%param p_delimiter - what is the delimiter value is for each field (default ',')
|
||||||
*/
|
*/
|
||||||
PROCEDURE export_table_to_csv(p_table IN VARCHAR2,
|
PROCEDURE export_table_to_csv(p_table IN VARCHAR2,
|
||||||
p_column_headers IN VARCHAR2,
|
p_column_headers IN VARCHAR2,
|
||||||
p_delimiter IN VARCHAR2 DEFAULT ',') is
|
p_delimiter IN VARCHAR2 DEFAULT ',') is
|
||||||
|
|
||||||
l_select VARCHAR2(2000); --will hold our dynamically created sql query
|
l_select VARCHAR2(2000); --will hold our dynamically created sql query
|
||||||
l_cursor INTEGER DEFAULT dbms_sql.open_cursor; --a handle for the recordset we can then loop through
|
l_cursor INTEGER DEFAULT dbms_sql.open_cursor; --a handle for the recordset we can then loop through
|
||||||
l_status INTEGER;
|
l_status INTEGER;
|
||||||
l_return VARCHAR2(4000);
|
l_return VARCHAR2(4000);
|
||||||
l_found BOOLEAN := TRUE;
|
l_found BOOLEAN := TRUE;
|
||||||
l_headers VARCHAR(2000); --used to collect the column headers
|
l_headers VARCHAR(2000); --used to collect the column headers
|
||||||
BEGIN
|
BEGIN
|
||||||
dbms_output.put_line('me is here');
|
dbms_output.put_line('me is here');
|
||||||
-- Build the dynamic SQL statement to get the tables column names
|
-- Build the dynamic SQL statement to get the tables column names
|
||||||
FOR f IN (SELECT column_name
|
FOR f IN (SELECT column_name
|
||||||
FROM user_tab_columns
|
FROM user_tab_columns
|
||||||
WHERE table_name = upper(p_table)
|
WHERE table_name = upper(p_table)
|
||||||
ORDER BY column_id) LOOP
|
ORDER BY column_id) LOOP
|
||||||
--
|
|
||||||
-- AG's clever delimiting ensures that the rows from the table are output
|
|
||||||
-- in a nice CSV format
|
|
||||||
l_select := l_select ||'''"''||'|| f.column_name || '||''"'||p_delimiter||'''||';
|
|
||||||
--
|
|
||||||
-- Get the header row, slightly inefficient in that we may not need to
|
|
||||||
-- do it every time
|
|
||||||
l_headers := l_headers || f.column_name || p_delimiter;
|
|
||||||
--
|
|
||||||
END LOOP;
|
|
||||||
--
|
|
||||||
-- Trim the unnecessary additional delimiting chars on the headers and
|
|
||||||
-- add a carriage return
|
|
||||||
l_headers := RTRIM(l_headers,p_delimiter) || CHR(13);
|
|
||||||
--
|
|
||||||
-- build the dynamic SQL that will return all the table rows
|
|
||||||
l_select := 'SELECT ' || RTRIM(l_select,'||') || CHR(13)||CHR(10) ||' FROM ' || p_table;
|
|
||||||
--
|
|
||||||
-- Now we have the select, let's execute it
|
|
||||||
--
|
|
||||||
dbms_output.put_line(l_select);
|
|
||||||
dbms_sql.parse(l_cursor
|
|
||||||
,l_select
|
|
||||||
,dbms_sql.native);
|
|
||||||
--
|
|
||||||
dbms_sql.define_column(l_cursor
|
|
||||||
,1
|
|
||||||
,l_return
|
|
||||||
,4000);
|
|
||||||
--
|
|
||||||
l_status := dbms_sql.execute(l_cursor); --could be used for further manipulation
|
|
||||||
--
|
|
||||||
WHILE (dbms_sql.fetch_rows(l_cursor) > 0) LOOP
|
|
||||||
--
|
|
||||||
IF l_found THEN
|
|
||||||
--
|
--
|
||||||
-- Set the header MIME type
|
-- AG's clever delimiting ensures that the rows from the table are output
|
||||||
owa_util.mime_header( 'application/octet', FALSE );
|
-- in a nice CSV format
|
||||||
-- Set the name of the file
|
l_select := l_select ||'''"''||'|| f.column_name || '||''"'||p_delimiter||'''||';
|
||||||
htp.p('Content-Disposition: attachment; filename="'||lower(p_table)||'.csv"');
|
|
||||||
-- Close the HTTP Header
|
|
||||||
owa_util.http_header_close;
|
|
||||||
--
|
--
|
||||||
l_found := FALSE;
|
-- Get the header row, slightly inefficient in that we may not need to
|
||||||
|
-- do it every time
|
||||||
|
l_headers := l_headers || f.column_name || p_delimiter;
|
||||||
--
|
--
|
||||||
-- If the user has requested that the tables column names be exported
|
END LOOP;
|
||||||
-- then display them
|
--
|
||||||
if upper(p_column_headers) = 'YES' then
|
-- Trim the unnecessary additional delimiting chars on the headers and
|
||||||
--print column headers
|
-- add a carriage return
|
||||||
htp.p(l_headers);
|
l_headers := RTRIM(l_headers,p_delimiter) || CHR(13);
|
||||||
end if;
|
--
|
||||||
|
-- build the dynamic SQL that will return all the table rows
|
||||||
|
l_select := 'SELECT ' || RTRIM(l_select,'||') || CHR(13)||CHR(10) ||' FROM ' || p_table;
|
||||||
|
--
|
||||||
|
-- Now we have the select, let's execute it
|
||||||
|
--
|
||||||
|
dbms_output.put_line(l_select);
|
||||||
|
dbms_sql.parse(l_cursor
|
||||||
|
,l_select
|
||||||
|
,dbms_sql.native);
|
||||||
|
--
|
||||||
|
dbms_sql.define_column(l_cursor
|
||||||
|
,1
|
||||||
|
,l_return
|
||||||
|
,4000);
|
||||||
|
--
|
||||||
|
l_status := dbms_sql.execute(l_cursor); --could be used for further manipulation
|
||||||
|
--
|
||||||
|
WHILE (dbms_sql.fetch_rows(l_cursor) > 0) LOOP
|
||||||
--
|
--
|
||||||
END IF;
|
IF l_found THEN
|
||||||
|
--
|
||||||
|
-- Set the header MIME type
|
||||||
|
owa_util.mime_header( 'application/octet', FALSE );
|
||||||
|
-- Set the name of the file
|
||||||
|
htp.p('Content-Disposition: attachment; filename="'||lower(p_table)||'.csv"');
|
||||||
|
-- Close the HTTP Header
|
||||||
|
owa_util.http_header_close;
|
||||||
|
--
|
||||||
|
l_found := FALSE;
|
||||||
|
--
|
||||||
|
-- If the user has requested that the tables column names be exported
|
||||||
|
-- then display them
|
||||||
|
if upper(p_column_headers) = 'YES' then
|
||||||
|
--print column headers
|
||||||
|
htp.p(l_headers);
|
||||||
|
end if;
|
||||||
|
--
|
||||||
|
END IF;
|
||||||
|
--
|
||||||
|
-- Main CSV output
|
||||||
|
dbms_sql.column_value(l_cursor
|
||||||
|
,1
|
||||||
|
,l_return);
|
||||||
|
--
|
||||||
|
htp.p(l_return);
|
||||||
|
--
|
||||||
|
END LOOP;
|
||||||
--
|
--
|
||||||
-- Main CSV output
|
END export_table_to_csv;
|
||||||
dbms_sql.column_value(l_cursor
|
|
||||||
,1
|
|
||||||
,l_return);
|
|
||||||
--
|
|
||||||
htp.p(l_return);
|
|
||||||
--
|
|
||||||
END LOOP;
|
|
||||||
--
|
|
||||||
END export_table_to_csv;
|
|
||||||
|
|
||||||
end MIP_FILES;
|
end MIP_FILES;
|
||||||
/
|
/
|
||||||
|
|||||||
Reference in New Issue
Block a user