SQL/MX Queuing and Publish/Subscribe Services
Embedded SQL Examples
HP NonStop SQL/MX Queuing and Publish/Subscribe Services—523734-002
3-3
Embedded DELETE
Embedded DELETE
Embedded DELETE statements enable applications to read and delete rows with a 
single operation. This example shows the use of an embedded DELETE with stream 
access and a holdable cursor. Note that after each fetch, the application commits its 
transaction and starts a new transaction before looping to fetch again.
---------------------------------------------------------------
#include <stdio.h> 
#include <string.h> 
long EmbeddedDelete()
{
 EXEC SQL BEGIN DECLARE SECTION;
 int destination; 
 int origin; 
 int seqnbr;
 long SQLCODE; 
 EXEC SQL END DECLARE SECTION; 
 EXEC SQL WHENEVER SQLERROR GOTO EndOfProcessing;
 /* Dequeue and route incoming parcels to next destination */
 EXEC SQL DECLARE arrivals CURSOR WITH HOLD FOR 
 SELECT destination, origin, seqnbr 
 FROM (DELETE FROM STREAM(inbox)) AS inbox; 
 EXEC SQL BEGIN WORK; /* Start transaction */
 EXEC SQL OPEN arrivals; 
 /* Wait for newly arrived parcels and notify receivers */
 while (1) { 
 /* Dequeue notifications */ 
 EXEC SQL FETCH arrivals 
 INTO :destination,:origin,:seqnbr;
 printf("\nDestination:%d Origin:%d "
 "Sequence number:%d",
 destination, origin, seqnbr);
 /* Route package and notify receivers
 routePackage(seqnbr, destination, origin);
 EXEC SQL COMMIT WORK; /* Commit transaction */
 EXEC SQL BEGIN WORK; /* Start new transaction */
 }
EndOfProcessing:
 EXEC SQL WHENEVER SQLERROR GOTO EndError;
 EXEC SQL CLOSE arrivals;
EndError:
 return SQLCODE;
} 
-----------------------------------------------------------










