Get_server_error_context

sql

FUNCTION Get_server_error_context (IN level INT, OUT itype INT, OUT par1 INT, OUT par2 INT, OUT par3 INT, OUT par4 INT, OUT objname CHAR(63)) RETURNS BOOLEAN;

Parameters

cdp client context variable
level context level
itype type of the returned context
par1 basic part of the returned context, usually the number of the object, that experienced an error (the absolute value in the system table of tables or objects)
par2 additional part of the returned context, if any
par3 additional part of the returned context, if any
par4 additional part of the returned context, if any
objname name of the object in par1 (only in SQL); if it's an object with local declaration (e.g. local declaration of a procedure), the local routine constant string will be here

Since version

7.0, SQL form since 8.1

Description

If this function is called after an error, it'll return the information about the error context. More information about errors and exception in SQL can be found here.

The level output parameter specifies the error context level. The function returns the smallest context for 0 and a wider context for higher values. If the level value is greater or equal to the defined number of context levels, the itype parameter will return 0 indicating that the higher levels don't need to be examined.

This function is often used in a loop for level values from 0 and above until itype returns 0.

The itype parameter returns the context type and the returned context type specifies the way of interpreting other parameters:

itype par1 par2 par3 par4
1 - table table number record number or -1 column number or 255 multiattribute value number or 65535
2 - index table number ordinal number of the index -- --
3 - procedure procedure number -- -- --
4 - trigger trigger number -- -- --
5 - SQL command -- -- -- --
6 - lock table number or -1 record or page number lock type blocking user
7 - compiling -- -- -- --
8 - record table number record number -- --
9 - index key -- -- -- --
0 - end -- -- -- --

The parameters designated with -- are not defined and are not interpreted.

The SQL variant of this function can be called not only when an error occurs (i.e. in a corresponding handler), but anywhere in a routine. Then function then doesn't get the error context, but may simulate e.g. the stack dump - see examples.

Function value

This function returns FALSE if successful, TRUE otherwise..

Example

PROCEDURE stack();
// displays the stack dump of routines into log
BEGIN
  DECLARE level,tp,p1,p2,p3,p4 INT; 
  DECLARE routine_name CHAR(63);
  SET level=0;
  cycle: LOOP
    CALL Get_server_error_context(level, tp, p1, p2, p3, p4, routine_name);
    IF tp=0 THEN LEAVE cycle; END IF;  // end
    IF tp=3 THEN      // display procedure name
      CALL Log_write('Procedure '+routine_name);
    ELSEIF tp=4 then  // display trigger name
      CALL Log_write('Trigger '+routine_name);
    ELSE
      CALL Log_write('Other type '+CAST(tp AS CHAR(4)));
    END IF;
    SET level=level+1;
  END LOOP;
END

See