5. Embedded SQL for Ada : Advanced Processing : User-Defined Error, DBevent, and Message Handlers : How to Declare User-Defined Handlers
 
Share this page                  
How to Declare User-Defined Handlers
The following example shows how to declare a handler for use in the set_sql errorhandler statement for ESQL/Ada:
exec sql include sqlca;

package Error_Trap is
        function Error_Func return Integer;
        pragma export_function (Error_Func);
end Error_Trap;

with text_io; use text_io;
with integer_text_io; use integer_text_io;

package body Error_Trap is
        function Error_Func return Integer is
        exec sql begin declare section;
                errnum : Integer;
        exec sql end declare section;
        begin
                exec sql inquire_sql(:errnum = ERRORNO);
                put ("Error number is: ");
                put (Errnum);
        end Error_Func;
end;

with Error_Trap; use Error_Trap;
procedure TEST is
begin
        exec sql connect dbname;

        exec sql set_sql (ERRORHANDLER = Error_Func);
          --
          -- ESQL will generate
          -- IILQshSetHandler ( 1, Error_Func'Address );
          --
          . . .
end;