Re: Capturing Ctrl-C in PRO*C program
Date: Thu, 19 May 1994 08:59:49 +0000
Message-ID: <769337989snz_at_istellar.demon.co.uk>
In article <Cpyqns.Eqs_at_ncrcae.ColumbiaSC.NCR.COM>
Rich.Cannon_at_ColumbiaSC.NCR.COM "Rich Cannon" writes:
> A friend of mine is using C and PRO*C as a user interface to an Oracle 7
> database. They are trying to capture a ctrl-C during an exec SQL on a long
> query so that they can break out of the query. Is there anyway to capture
> this Ctrl-C while the query is running or otherwise get out of the query?
There surely is...Add the following chunks of code into your Pro*C program:
/* Function protos */
void ora_interrupt();
char ret_char();
void close_down_failure(); /* This is basically EXEC SQL ROLLBACK WORK RELEASE */
/* Function called by signal(SIGINT) */
void ora_interrupt()
{
char answer[5];
fprintf( stderr, "ABORT (Y/N) ? " );
answer[0] = ret_char();
if ( answer[0] == 'Y' || answer[0] == 'y' )
close_down_failure();
else
return;
}
char ret_char()
{
int tmp_char;
struct termio torig,
traw;
ioctl( 0, TCGETA, &torig );
traw = torig;
traw.c_lflag &= ~ICANON; traw.c_cc[VMIN] = 1; traw.c_cc[VTIME] = 0;
ioctl( 0, TCSETA, &traw );
tmp_char = getchar();
ioctl( 0, TCSETA, &torig );
return( tmp_char );
}
Now, here's a chunk of sample code to show you how to call these functions:
EXEC SQL OPEN test_cursor;
fprintf( stderr, "Enabling interrupts!\n" );
for ( ; ; )
{
EXEC SQL FETCH test_cursor /* Fetches the cursor values */ INTO :tmp_value; signal( SIGINT, ora_interrupt ); /* If an interrupt is caught */ } /* run ora_interrupt() */
fprintf( stderr, "Disabling interrupts!\n" );
> Thanks
Pleasure. Any problems, give me a shout.
-- Alligator Descartes v_at_istellar.demon.co.ukReceived on Thu May 19 1994 - 10:59:49 CEST