ID Number: Q39124
1.10 1.11 4.20
OS/2
Summary:
The following is a description of how to gracefully interrupt a
workstation DB-LIBRARY (db-lib) application from the keyboard
with CTRL+C while it is receiving data from SQL Server.
More Information:
Set up a signal handler for CTRL+C using the function signal() or
DosSetSigHandler() [in MS-DOS, use signal(); in OS/2, use either
signal() or DosSetSigHandler()]. This handler should set a flag
that is tested inside the dbnextrow() loop. If the flag is set,
call dbcancel() instead of dbnextrow(). This notifies SQL Server
not to send any more data and flushes anything that has already
been sent. Then bail out of the dbnextrow() loop.
This technique will not interrupt the processing of a long-running
db-lib function call such as dbprrow(). The signal handler will set
the flag, but the flag will not be tested until db-lib returns control
to the application program. A solution is to use the optional timeout
feature of db-lib. This will cause your error handler to get control
when the timeout period expires. Your error handler can then test
the flag set by the signal handler and return DBCANCEL if set.
The dbsetinterrupt() technique will not interrupt a db-lib function
when it is waiting for the SQL Server to send data because db-lib does
a blocked read on the named pipe. The signal handler will set the flag
(OS/2 only), but the routine registered by dbsetinterrupt() to test
that flag will not execute until the blocked read completes.
If you need to interrupt applications that are waiting for output from
SQL Server, the best approach is not to do the blocking read until the
data has arrived. Use dbdataready() to determine if data has already
been sent before calling db-lib functions that do blocking reads
[dbsqlexec() and dbsqlok()].
If you call dbcancel() directly from the signal handler, it may
execute while another db-lib function call is in progress. This can
cause db-lib to get out of sync with the SQL Server data stream. In
this case, db-lib may do a blocking read when there is nothing to be
read, causing an endless wait.
Additional reference words: dblib