SQL/MX Queuing and Publish/Subscribe Services
Embedded SQL Examples
HP NonStop SQL/MX Queuing and Publish/Subscribe Services—523734-002
3-9
Join With a Stream
This program illustrates an embedded DELETE accessing a table as a stream, joined 
to a regular table:
---------------------------------------------------------------
#include <stdio.h> 
#include <string.h> 
long EmbeddedDelete() 
{
 EXEC SQL BEGIN DECLARE SECTION;
 int destination; 
 int origin; 
 int seqnbr;
 int hub;
 long SQLCODE; 
 EXEC SQL END DECLARE SECTION; 
 EXEC SQL WHENEVER SQLERROR GOTO EndOfProcessing;
 /* Route incoming parcels to next destination */
 EXEC SQL DECLARE arrivals CURSOR FOR 
 SELECT inbox.destination, inbox.origin, 
 inbox.seqnbr, routes.hub 
 FROM (DELETE FROM STREAM(inbox)) AS inbox, routes
 WHERE inbox.destination = routes.destination 
 AND inbox.origin = routes.origin; 
 EXEC SQL CONTROL QUERY DEFAULT materialize reset;
 EXEC SQL OPEN arrivals; 
 /* Wait for newly arrived parcels and notify receivers */
 while (1) { 
 /* Wait for notifications */ 
 EXEC SQL FETCH arrivals 
 INTO :destination,:origin,:seqnbr,:hub;
 printf("\nDestination:%d Origin:%d " 
 "Sequence number:%d Hub:%d",
 destination, origin, seqnbr, hub);
 /* Route package to intermediate hub */
 routePackage(seqnbr, hub); 
 }
EndOfProcessing:
 EXEC SQL WHENEVER SQLERROR GOTO EndError;
 EXEC SQL CLOSE arrivals;
EndError:
 return SQLCODE;
} 
-----------------------------------------------------------










