Allow a user to interrupt

When the database server processes a large query, you might want to allow the user to interrupt the query request with the Interrupt key (usually CTRL-C).

To do this, you must set up a signal-handler function. The signal-handler function is a user-defined function that the application process calls when it receives a specific signal.

To allow the user to interrupt an SQL request, you define a signal-handler function for the SIGINT signal. This function must have the following declaration:
void sigfunc_ptr();

The user-defined signal-handler function can contain the control functions sqlbreak() and sqldone(). If you use any other control function or any SQL statement in the signal handler while the database server is processing, generates an error (-439).

The application must determine how to continue execution after the signal handler completes. One possible method is to set up a nonlocal go to with the setjmp() and longjmp() system functions. These functions work together to support low-level interrupts, as follows:
  • The setjmp() function saves the current execution environment and establishes a return point for execution after the longjmp() call.
  • The longjmp() call is in the signal-handler function. Use longjmp() in a signal-handling function only if sqldone() returns 0 (the database server is idle).

See your UNIX™ operating system documentation for more information about the setjmp() and longjmp() system functions.

To associate the user-defined signal handler with a system signal, use the signal() system function, as follows:
signal(SIGINT, sigfunc_ptr);

When the application receives the SIGINT signal, it calls the function that sigfunc_ptr indicates. For more information about the signal() system function, see your UNIX operating system documentation.

To disassociate the signal-handler function from the SIGINT signal, call signal() with SIG_DFL as the function pointer, as follows:
signal(SIGINT, SIG_DFL);
SIG_DFL is the default signal-handling action. For the SIGINT signal, the default action is to stop the process and to generate a core dump. You might instead want to specify the SIG_IGN action to cause the application to ignore the signal.
Important: On most systems, the signal handler remains in effect after the application catches the signal. On these systems, you need to disassociate the signal handler explicitly if you do not want it to execute the next time the same signal is caught.

On a few (mostly older) systems, however, when a signal handler catches a signal, the system reinstates the SIG_DFL action as the handling mechanism. On these systems, it is up to the signal handler to reinstate itself if you want it to handle the same signal the next time the signal is caught. For information about how your system handles signals, check your system documentation.