protected static List < VoltXMLElement > voltGetLimitOffsetXMLFromSortAndSlice ( Session session , SortAndSlice sortAndSlice ) throws HSQLParseException { List < VoltXMLElement > result = new ArrayList <> ( ) ; if ( sortAndSlice == null || sortAndSlice == SortAndSlice . noSort ) { return result ; } if ( sortAndSlice . limitCondition != null ) { Expression limitCondition = sortAndSlice . limitCondition ; if ( limitCondition . nodes . length != 2 ) { throw new HSQLParseException ( "Parser did not create limit and offset expression for LIMIT." ) ; } try { // read offset. it may be a parameter token. VoltXMLElement offset = new VoltXMLElement ( "offset" ) ; Expression offsetExpr = limitCondition . getLeftNode ( ) ; if ( offsetExpr . isParam == false ) { Integer offsetValue = ( Integer ) offsetExpr . getValue ( session ) ; if ( offsetValue > 0 ) { Expression expr = new ExpressionValue ( offsetValue , org . hsqldb_voltpatches . types . Type . SQL_BIGINT ) ; offset . children . add ( expr . voltGetXML ( session ) ) ; offset . attributes . put ( "offset" , offsetValue . toString ( ) ) ; } } else { offset . attributes . put ( "offset_paramid" , offsetExpr . getUniqueId ( session ) ) ; } result . add ( offset ) ; // Limit may be null (offset with no limit), or // it may be a parameter Expression limitExpr = limitCondition . getRightNode ( ) ; if ( limitExpr != null ) { VoltXMLElement limit = new VoltXMLElement ( "limit" ) ; if ( limitExpr . isParam == false ) { Integer limitValue = ( Integer ) limitExpr . getValue ( session ) ; Expression expr = new ExpressionValue ( limitValue , org . hsqldb_voltpatches . types . Type . SQL_BIGINT ) ; limit . children . add ( expr . voltGetXML ( session ) ) ; limit . attributes . put ( "limit" , limitValue . toString ( ) ) ; } else { limit . attributes . put ( "limit_paramid" , limitExpr . getUniqueId ( session ) ) ; } result . add ( limit ) ; } } catch ( HsqlException ex ) { // XXX really? ex . printStackTrace ( ) ; } } return result ; }
return a list of VoltXMLElements that need to be added to the statement XML for LIMIT and OFFSET