88 lines
2.9 KiB
Plaintext
88 lines
2.9 KiB
Plaintext
CREATE TABLE mmt_staging2.mmt_DB_Run_Status
|
|
( syspk bigserial NOT NULL,
|
|
client_id int,
|
|
function_id int,
|
|
user_id int,
|
|
user_name text,
|
|
file_syspk int,
|
|
file_format text,
|
|
sheet_mnemonic text,
|
|
block_name text,
|
|
staging_type text,
|
|
error_function text,
|
|
error_state text,
|
|
error_message text,
|
|
error_detail text,
|
|
error_hint text,
|
|
error_context text,
|
|
status text,
|
|
error_timestamp timestamp default now(),
|
|
CONSTRAINT mmt_DB_error_pkey PRIMARY KEY (syspk)
|
|
);
|
|
|
|
drop table mmt_staging2.mmt_DB_Errors;
|
|
ALTER TABLE mmt_staging2.mmt_DB_Errors
|
|
ADD status text;
|
|
|
|
DROP FUNCTION IF EXISTS mmt_staging2.mmt_insert_DB_error;
|
|
|
|
CREATE OR REPLACE FUNCTION mmt_staging2.mmt_insert_db_error( clientId int, functionId int, userId int, userName varchar, fileSyspk int,
|
|
fileFormat varchar,sheetMnemonic varchar,blockName varchar,stagType varchar, eFunction varchar, eState varchar, eMessage varchar, eDetail varchar, eHint varchar,eContext varchar, sta varchar)
|
|
RETURNS text AS $$
|
|
DECLARE
|
|
_message_text text;
|
|
_returned_sqlstate text;
|
|
BEGIN
|
|
BEGIN
|
|
INSERT INTO mmt_staging2.mmt_DB_Run_Status ( client_Id, function_id, user_id, user_name, file_syspk, file_format, sheet_mnemonic, block_name, staging_type, error_function, error_state, error_message, error_detail, error_hint, error_context,status)
|
|
values ( clientId, functionId, userID, userName, fileSyspk, fileFormat, sheetMnemonic, blockName, stagType, eFunction, eState, eMessage, eDetail, eHInt, eContext, sta );
|
|
|
|
EXCEPTION when OTHERS THEN
|
|
_message_text := '';
|
|
_returned_sqlstate := '';
|
|
|
|
GET STACKED DIAGNOSTICS
|
|
_message_text = MESSAGE_TEXT,
|
|
_returned_sqlstate = RETURNED_SQLSTATE;
|
|
|
|
RETURN 'Failed: DB Error Creation : ' || _returned_sqlstate || ' : ' || _message_text;
|
|
END;
|
|
RETURN 'Success: DB Error Creation ';
|
|
END
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
DROP FUNCTION IF EXISTS mmt_staging2.test_mmt_db_error;
|
|
|
|
CREATE OR REPLACE FUNCTION mmt_staging2.test_mmt_db_error ()
|
|
RETURNS text AS $$
|
|
DECLARE
|
|
v_state text;
|
|
v_msg text;
|
|
v_detail text;
|
|
v_hint text;
|
|
v_context text;
|
|
v_block text;
|
|
begin
|
|
v_block := 'nothing';
|
|
CREATE TABLE t_test( test_id int);
|
|
v_block := 'nothing';
|
|
CREATE TABLE t_test(test_id int); -- this will cause an error
|
|
|
|
EXCEPTION when OTHERS then
|
|
|
|
GET STACKED DIAGNOSTICS
|
|
v_state = returned_sqlstate,
|
|
v_msg = message_text,
|
|
v_detail = pg_exception_detail,
|
|
v_hint = pg_exception_hint,
|
|
v_context = pg_exception_context;
|
|
|
|
perform mmt_staging2.mmt_insert_db_error ( 10, 1, 1001, 'Compegence',1,'ftdry','ftdry_trs',v_block,'stg2', 'test_db_error', v_state, v_msg, v_detail, v_hint, v_context,'error');
|
|
|
|
return v_block;
|
|
END;
|
|
$$ LANGUAGE plpgsql;
|
|
|
|
select mmt_staging2.test_mmt_db_error ()
|
|
select * from mmt_staging2.mmt_DB_Errors
|
|
delete from mmt_staging2.mmt_DB_Errors; |