6. Embedded SQL for BASIC : 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/BASIC:
! Main program

program error_trap
    exec sql include sqlca
    external integer error_func         ! declare error handler
    exec sql connect dbname
    exec sql set_sql (errorhandler = error_func)
!
!    esql will generate
!    call iilqshsethandler (1, error_func)
!
    . . .
end program

function integer error_func()
exec sql include sqlca

exec sql begin declare section
        declare integer errnum
exec sql end declare section
        exec sql inquire_sql (:errnum = errorno)
        print 'error number is ' + str$(errnum)
end function