The callback function
With the sqlbreakcallback() function, you also specify a callback function to be called at several points in the execution of an SQL request.
void callbackfunc(status)
mint status;
Point at which callback is called | Callback argument value |
---|---|
After the database server has completed the SQL request | 0 |
Immediately after the application sends an SQL request to the database server | 1 |
While the database server is processing an SQL request, after the timeout interval has elapsed | 2 |
For more information about message requests, see Interruptible SQL statements.
- The sqldone() library function determines whether
the database server is still busy.
If sqldone() returns error
-439
, the database server is still busy and you can proceed with the interrupt. - The sqlbreakcallback() library function disassociates
the callback function from the timeout interval. Call sqlbreakcallback() with the following arguments:
sqlbreakcallback(-1L, (void *)NULL);
This step is not necessary if you want the callback function to remain for the duration of the current connection. When you close the current connection, you also disassociate the callback function.
- The sqlbreak() library function interrupts the execution of the database server.
If you use any control function other than those in the preceding list, or if you use any SQL statement while the database server is processing, generates an error (-439).
- To continue execution of the SQL request, the callback function
skips the call to sqlbreak().
While the callback function executes, the database server continues processing its SQL request. After the callback function completes, the application waits for another timeout interval before it calls the callback function again. During this interval, the database server continues execution of the SQL request.
- To cancel the SQL request, the callback function calls the sqlbreak() function,
which sends an interrupt request to the database server.
Execution of the callback function continues immediately after sqlbreak() sends the request. The application does not wait for the database server to respond until it completes execution of the callback function.
When the database server receives the interrupt request signal, it determines if the current SQL request is interruptible (see Interruptible SQL statements). If so, the database server discontinues processing and returns control to the application. The application is responsible for the graceful termination of the program; it must release resources and roll back the current transaction. For more information about how the database server responds to an interrupt request, see the description of sqlbreak() in Database server control functions.
sqlbreakcallback(timeout, callbackfunc_ptr);
void callbackfunc_ptr();
The timeout demonstration program, which Database server control functions describes, uses the sqlbreakcallback() function to establish a timeout interval for a database query.