SQL/MX Queuing and Publish/Subscribe Services
Embedded SQL Examples
HP NonStop SQL/MX Queuing and Publish/Subscribe Services—523734-002
3-2
Stream Access
Stream Access
The stream access mode enables applications to access regular tables as continuous 
data streams. The stream access mode first does a regular scan of the table. Then, if 
all available rows have been retrieved, the stream access mode causes fetch 
operations to wait (block) instead of returning the end-of-data condition.
This program illustrates the stream access mode with no embedded DELETE or 
UPDATE operation:
---------------------------------------------------------------
#include <stdio.h> 
#include <string.h> 
long StreamParcels()
{
 EXEC SQL BEGIN DECLARE SECTION;
 int destination; 
 int origin; 
 int seqnbr;
 long SQLCODE;
 EXEC SQL END DECLARE SECTION; 
 EXEC SQL WHENEVER SQLERROR GOTO EndOfProcessing;
 /* Routes incoming parcels to their destination */
 EXEC SQL DECLARE arrivals CURSOR FOR 
 SELECT destination, origin, seqnbr 
 FROM (SELECT * FROM STREAM(inbox)) AS inbox; 
 EXEC SQL OPEN arrivals; 
 /* Wait for newly arrived parcels and notify receivers */
 while (1) { 
 /* Fetch notifications */ 
 EXEC SQL FETCH arrivals 
 INTO :destination,:origin,:seqnbr;
 printf("\nDestination:%d Origin:%d " 
 "Sequence Number:%d",
 destination, origin, seqnbr);
 /* Route package, notify receivers */
 routePackage(seqnbr, destination, origin); 
 }
EndOfProcessing:
 EXEC SQL WHENEVER SQLERROR GOTO EndError;
 EXEC SQL CLOSE arrivals;
EndError:
 return SQLCODE;
} 
------------------------------------------------------------










