getNextPageFromOffset() and getPreviousPageFromOffset()
While paging a result set, you can skip a number of rows or records. This set of records to be skipped is called an Offset. Use the Database.getNextPageFromOffset() and Database.getPreviousPageFromOffset() functions to get the next or previous pages respectively of the database cursor, starting from an offset.
Syntax
Object [] getNextPageFromOffset(String cursorName, int startOffset, int pageSize) Object [] getPreviousPageFromOffset (String cursorName, int startOffset, int pageSize)
Parameters
Parameter | Type | Description |
---|---|---|
cursorName | String | The name of the database cursor. |
startOffset | Integer | The start offset for the page. |
pageSize | Integer | The number of concepts or records to be fetched from the database for each page.
If the pageSize is -1, then the default page size given for the cursor is used. The default is 500. |
return Object[] | Object[] | The array of the returned resultset data.
If resultConceptURI is specified, the array is of resultConceptType. Else, it is in the form of n-tuple object array, where each tuple is an array of the values of the returned resultset data. |
Example for getNextPageFromOffset
Database.setCurrentConnection("/SharedResources/Oracle.sharedjdbc"); String jdbcURI="/SharedResources/HR_DB_Conn.sharedjdbc"; String cursorName="EmpCursor"; String resultTypeURI="/Concepts/HR/EMPLOYEES"; String sql="select * from employees"; int pageSize=10 ; Object requestObj=null; String cursorName=Database.createQuery(jdbcURI,cursorName,resultTypeURI,sql,pageSize,requestObj); System.debugOut(" Opened Cursor: " + cursorName); Concept[] empCepts={}; empCepts=Database.getNextPageFromOffset(cursorName,2,10); System.debugOut(" Database. getPreviousPage () fetched " + empCepts@length + " rows");
Example for getPreviousPageFromOffset
Database.setCurrentConnection("/SharedResources/Oracle.sharedjdbc"); String jdbcURI="/SharedResources/HR_DB_Conn.sharedjdbc"; String cursorName="EmpCursor"; String resultTypeURI="/Concepts/HR/EMPLOYEES"; String sql="select * from employees"; int pageSize=10 ; Object requestObj=null; String cursorName=Database.createQuery(jdbcURI,cursorName,resultTypeURI,sql,pageSize,requestObj); System.debugOut(" Opened Cursor: " + cursorName); Concept[] empCepts={}; empCepts=Database.getPreviousPageFromOffset(cursorName,5,10); System.debugOut(" Database. getPreviousPage () fetched " + empCepts@length + " rows");
Copyright © Cloud Software Group, Inc. All rights reserved.