Added support for 'friendly' database constraint messages.
Changed SUPP role type description following training session. git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@3628 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
82
Modules/mip_friendly_messages.pck
Normal file
82
Modules/mip_friendly_messages.pck
Normal file
@@ -0,0 +1,82 @@
|
||||
CREATE OR REPLACE PACKAGE mip_friendly_messages IS
|
||||
|
||||
-- Author : HARDYA
|
||||
-- Created : 19/02/2008 09:45:09
|
||||
-- Purpose :
|
||||
|
||||
/** Attempt to produce a user friendly message for an Oracle message
|
||||
%param p_ora_msg the message to be processed
|
||||
%return either a friendly message or p_ora_msg
|
||||
*/
|
||||
FUNCTION get_friendly_message(p_ora_msg IN VARCHAR2) RETURN VARCHAR2;
|
||||
|
||||
END mip_friendly_messages;
|
||||
/
|
||||
CREATE OR REPLACE PACKAGE BODY mip_friendly_messages IS
|
||||
|
||||
FUNCTION get_constraint_message(p_ora_msg IN VARCHAR2) RETURN VARCHAR2 IS
|
||||
c_marker CONSTANT VARCHAR2(30) := 'constraint (';
|
||||
c_marker_length CONSTANT NUMBER := length(c_marker);
|
||||
l_msg constraint_messages.msg%TYPE;
|
||||
l_constraint VARCHAR2(30);
|
||||
l_constraint_name VARCHAR2(30);
|
||||
l_start_posn NUMBER;
|
||||
l_end_posn NUMBER;
|
||||
BEGIN
|
||||
-- get the complete constraint "user.constraint_name"
|
||||
l_start_posn := instr(p_ora_msg
|
||||
,c_marker) + c_marker_length;
|
||||
l_end_posn := instr(p_ora_msg
|
||||
,')'
|
||||
,l_start_posn) - 1;
|
||||
l_constraint := substr(p_ora_msg
|
||||
,l_start_posn
|
||||
,l_end_posn - l_start_posn + 1);
|
||||
|
||||
-- get the "constraint_name"
|
||||
l_start_posn := instr(l_constraint
|
||||
,'.') + 1;
|
||||
l_constraint_name := substr(l_constraint
|
||||
,l_start_posn);
|
||||
|
||||
BEGIN
|
||||
SELECT msg
|
||||
INTO l_msg
|
||||
FROM constraint_messages
|
||||
WHERE constraint_name = l_constraint_name;
|
||||
EXCEPTION
|
||||
WHEN no_data_found THEN
|
||||
l_msg := NULL;
|
||||
END;
|
||||
IF l_msg IS NULL
|
||||
AND l_constraint_name LIKE 'SYS!_C%' ESCAPE '!'
|
||||
OR l_constraint_name LIKE 'AVCON!_%' ESCAPE '!' THEN
|
||||
-- this is a system generated check constraint and should not be appearing
|
||||
l_msg := 'Application error. Attempting to violate check constraint ' ||
|
||||
l_constraint_name ||
|
||||
'. Please report this error to Advantica.';
|
||||
END IF;
|
||||
RETURN l_msg;
|
||||
END;
|
||||
|
||||
FUNCTION get_friendly_message(p_ora_msg IN VARCHAR2) RETURN VARCHAR2 IS
|
||||
l_ora_msg VARCHAR2(240) := p_ora_msg;
|
||||
l_sqlcode NUMBER;
|
||||
l_msg VARCHAR2(2000);
|
||||
BEGIN
|
||||
l_sqlcode := substr(l_ora_msg
|
||||
,1
|
||||
,5);
|
||||
IF instr(l_ora_msg
|
||||
,'constraint (') > 0 THEN
|
||||
l_msg := nvl(get_constraint_message(l_ora_msg)
|
||||
,l_ora_msg);
|
||||
ELSE
|
||||
l_msg := l_ora_msg;
|
||||
END IF;
|
||||
|
||||
htp.prn(l_msg);
|
||||
END get_friendly_message;
|
||||
|
||||
END mip_friendly_messages;
|
||||
/
|
||||
Reference in New Issue
Block a user