Re: SQLBreak function
Posted in 1998
David Kosenko wrote:
>
> Also sprach "Rui Domingos" <rui.domingos@psidoc.pt> :
> :Can anyone give an exmple on using the SQLBreak function using ESQL/C?
>
> You'll typically use sqlbreak() in a signal catching routine, so when the user
> hits the interrupt key, the signal is caught and sqlbreak() is used to send the
> appropriate interrupt to the server. You also want to use sqldone() to verify
> that the server is currently in the midst of some processing on your behalf,
> else there is no reason to send an sqlbreak() in the first place.
>
> Here's a sample (adopted from the latest ESQL/C training manual):
>
> void catch_alrm(int sig)
> {
> if (sqldone() == -439)
> //Database server is currently processing an SQL task.
> {
> sqlbreak();
> }
> }
>
> main()
> {
> signal(SIGINT, catch_alrm);
> // rest of program
> }
I just want to add handling of the interrupt after the SQL. So if your
SQL error handler, called after each SQL statement, is:
int SQLErrorHandle( char *WhereAmI, char *file, int line )
{
if (sqlca.sqlcode == -213) {
fprintf( stderr, "Interrupted while %s, file: %s, line: %d.\\n",
WhereAmI, file, line );
return -1;
} else if sqlca.sqlcode < 0) {
fprintf( stderr,
"SQL Error #%d(%d) returned while %s. File: %s, line: %d.\\n",
sqlca.sqlcodesqlca.sqlerrd[1], WhereAmI, file, line );
return 1;
} else
return 0;
}
Then you can check for interruptions and cleanup:
EXEC SQL FETCH my_curs INTO :mystruct;
if ((err=SQLErrorHandle("FETCHING my_curs", __FILE__, __LINE__ ))==-1)
CleanUpAfterInterrupt();
else if (err == 1)
exit(99);
Art S. Kagel