SQL/MX Queuing and Publish/Subscribe Services
Embedded SQL Examples
HP NonStop SQL/MX Queuing and Publish/Subscribe Services—523734-002
3-13
Managing Transactions With the Stream Timeout
Attribute
set to 30 seconds, so that when it has deleted all available rows, the final transaction
lasts no more than 30 seconds.
---------------------------------------------------------------
#include "stdio.h"
#include "stdlib.h"
#include "assert.h"
const int TRUE = 1;
const int FALSE = 0;
/* This global variable is set to TRUE by the
handle_error_or_timeout() function and read
and reset to FALSE by the main() function. */
int timed_out = FALSE;
void handle_error_or_timeout(void);
EXEC SQL MODULE cat.sch.DEFERTRANS NAMES ARE ISO88591;
int main(int argc, char *argv[])
{
EXEC SQL BEGIN DECLARE SECTION;
int hv_a;
long SQLCODE;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR CALL handle_error_or_timeout;
for (;;) /* begin outer loop */
{
/* -1 means unlimited duration stream_timeout */
exec sql control query default STREAM_TIMEOUT '-1';
exec sql select a into :hv_a
from stream(t)
where a >= 0
for read uncommitted access;
/* If program logic comes here, it is because
there might be at least one row to delete.
Now start deleting rows until stream timeout
error is raised, which indicates there are
no more rows. Notice that we have not yet
started a transaction, or locked any record.
The longest transaction or record lock will be
the determined by the STREAM_TIMEOUT setting
below, 30 seconds.
*/
for (;;) /* begin inner loop */