databaseuniverseu2unidatau2netdk

How to do fetch pages when querying universe database using .net sdk and sql


I am connecting to a universe database (from rocket software) using their .net driver. I would like to fetch data on demand on user request per page i.e. do pagination. With other databases we could use (offset fetch) but universe db doesn't seem to support it. It does not recognize keyword offset, something like SELECT NAME, AGE FROM CONTACTS WHERE AGE > 25 offset 5 sample 5 does not work. I does not recognize those keywords and there is no good documentation :-(

Note: Although it is traditionally a multi-value database, the one I am using does not use multi value types but the structure is normalized.


Solution

  • This is certainly one of the shortcomings of this platform. I have worked through this in the past with the something similar to the following subroutine. I had to remove a bunch of stuff for brevity but this compiles so it must work completely bug free, right?

    Caveats: You need to have @SELECT DICT item in each file you want to use this with containing all of the columns you want to return.

    Multivalues get a little tricky. I had flattened the data I was using this with so I did not run into that problem, but this does not do UNNESTs.

    Also you might want to add a value saying how many records there are total and possibly work out some kind of token passing and list saving to cut down on executing the query each time you run it but that gets much, much deeper than the basic question at hand.

    SUBROUTINE SQLSelectWithOffset(TableName,UVWithClause,Starting,Offset)
    ***********************************************************************
    * PROGRAM ID:     SQLSelectWithOffset
    *
    * PROGRAM TITLE:  SQLSelectWithOffset
    *
    * DESCRIPTION:    Universe doesn't support sql commands using starting and offset
    *                 which makes life hard when you want all of a file
    *                 but you choke on the size. Tokens allow for the selectlist to be saved
    *                 TableName = UV FIle to select on. If this is blank program will return the number of records remaining
    *                 UVWithClause = Your critera, WITH or BY criteria you want in a sort select. 
    *                 Starting = Holds you place in line
    *                 Offest = How many records to return 
    ************************************************************************
      $INCLUDE UNIVERSE.INCLUDE ODBC.H
      RETURN.LIST = ""
      IF Starting = "" or Starting < 1 THEN
         Starting = 1
      END
      GOSUB GET.MASTER.LIST
      FOR X=Starting TO Offset
         ID = EXTRACT(FULL.LIST,X,0,0)
         IF ID = "" THEN CONTINUE
         RETURN.LIST<-1> = ID
      NEXT X
      SELECT RETURN.LIST TO 9
      SQLSTMT ="SELECT * FROM ":TableName:" SLIST 9"
      ST=SQLExecDirect(@HSTMT, SQLSTMT)
    RETURN
    GET.MASTER.LIST:
      STMT = "SSELECT ":TableName
      IF UVWithClause NE "" THEN
         STMT := " ":UVWithClause
      END
      EXECUTE "CLEARSELECT"
      EXECUTE STMT
      READLIST FULL.LIST ELSE FULL.LIST = ""
    
    RETURN
    
    END
    

    Good luck, please only use this information for good!