SQL/MX Queuing and Publish/Subscribe Services
Embedded SQL Examples
HP NonStop SQL/MX Queuing and Publish/Subscribe Services—523734-002
3-7
Rowset Integration
EXEC SQL FETCH arrivals
INTO :destination,:origin,:seqnbr,:abortcount;
printf("\nDestination:%d Origin:%d "
"Sequence number:%d Abortcount:%d",
destination, origin, seqnbr, abortcount);
/* Route package and notify receiver */
routePackage(seqnbr, destination, origin);
EXEC SQL COMMIT WORK;
EXEC SQL BEGIN WORK; /* Start new transaction */
}
EndOfProcessing:
EXEC SQL WHENEVER SQLERROR GOTO EndError;
EXEC SQL CLOSE arrivals;
EndError:
return SQLCODE;
}
------------------------------------------------------------
Rowset Integration
Applications can use rowsets to enqueue or dequeue multiple rows at one time instead
of having to enqueue or dequeue rows one at a time. This program illustrates
dequeueing rowsets and the skip conflict access mode:
---------------------------------------------------------------
#include <stdio.h>
#include <string.h>
long DequeueRowsets()
{
EXEC SQL BEGIN DECLARE SECTION;
ROWSET[10] int arrayDestination;
ROWSET[10] int arrayOrigin;
ROWSET[10] int arraySeqnbr;
long numFetched;
short i;
long SQLCODE;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR GOTO EndOfProcessing;
EXEC SQL DECLARE arrivals CURSOR WITH HOLD FOR
SELECT destination, origin, seqnbr
FROM (DELETE FROM STREAM(inbox)
FOR SKIP CONFLICT ACCESS) AS inbox;
EXEC SQL BEGIN WORK; /* Start transaction */
EXEC SQL OPEN arrivals;
/* Wait for newly arrived parcels and notify receivers */
Note. Rowset integration is not supported in Java applications that contain embedded
SQL/MX statements.