compile Insert RTI_MVBFS_SERVER_PLUGIN_UNIVERSE_SOURCE

/*
* This insert contains the source for a program to install on the U2 server
* The program will support efficient record selection
* I used conditional compilation to prevent compiling in oi
*/
#UNDEFINE _IGNORE_THE_FOLLOWING_
#IFDEF _IGNORE_THE_FOLLOWING_
SUBROUTINE RTI_MVBFS_SERVER_PLUGIN_UNIVERSE( METHOD, COMMANDS, OILIST, UNIQUEID, RESULTS)
*
*
* THIS SUBROUTINE IS USED FOR EXECUTING A CHAIN OF QUERIES ON U2, RETURNING THE KEYS TO OI
* SEE RTI_CHAIN_SELECT.
*
* 03/24/19   rjc  Created from D3 version
* **********************************
*
* Selectinfo equates
$INCLUDE UNIVERSE.INCLUDE INFO_KEYS.INS.IBAS

EQU TRUE TO 1, FALSE TO 0
EQU AM TO CHAR(254), VM TO CHAR(253), SVM TO CHAR(252), FM TO CHAR(254)


 RESULTS = ""

* cursorvar will be a list variable ( not a dynamic array)
* used to pass keys from one select into the next
 CURSORVAR = ""


*  Cannot test list variables directly, so keep a LIST.ACTIVE flag
 LIST.ACTIVE = ( OILIST <> "" )

* Did they pass a list of keys from OI? Load into cursorvar
 IF LIST.ACTIVE NE "" THEN
	  FORMLIST OILIST
	  READLIST CURSORVAR ELSE LIST.ACTIVE = FALSE
 END

* Run the commands

CMD_CNT = DCOUNT(COMMANDS, AM)

FOR WHICH_COMMAND = 1 TO CMD_CNT

	  CMD = COMMANDS<WHICH_COMMAND>

	  CONTINUE = ( CMD # "" ) AND ( WHICH_COMMAND = 1  OR  LIST.ACTIVE )

	  IF CONTINUE THEN

		   IF LIST.ACTIVE  THEN
				EXECUTE CMD PASSLIST CURSORVAR
		   END ELSE
				EXECUTE CMD
		   END

		   * Save the keys from the last select to pass to the next select
		   LIST.ACTIVE = SELECTINFO(0,IK$SLACTIVE)
		   IF LIST.ACTIVE THEN
				 READLIST CURSORVAR ELSE LIST.ACTIVE = FALSE
		   END

	  END

NEXT WHICH_COMMAND

*
* Return results as @fm delimited list
* 
IF LIST.ACTIVE  THEN
     IF UNIQUEID <> "" And Len(CURSORVAR) > 32000 Then
         WRITELIST CURSORVAR ON UNIQUEID
         RESULTS = "?":UNIQUEID:"?"
     END Else
         RESULTS = CURSORVAR
     END
END

RETURN

End
#ENDIF
