Example #1
0
  public override void FetchTo( ResultSet rs, EvalEnv e )
  {
    ResultSet srs = Order == null ? rs : new Sorter( rs, SortSpec );
    srs = GroupSpec == null ? srs : new Grouper( srs, GroupSpec, AggSpec );

    Value[] tr = new Value[ TE.Cols.Count ];

    EvalEnv ee = new EvalEnv( e.Locals, tr, e.ResultSet );

    IdSet idSet = Where == null ? null : Where.GetIdSet( TE, ee );
    if ( idSet != null ) idSet = new IdCopy( idSet, ee ); // Need to take a copy of the id values if an index is used.

    rs.NewTable( Cols );

    Value [] outrow = new Value[ Exps.Count ]; 

    if ( idSet != null ) 
    // Fetch subset of source table using id values, send to ResultSet (if it satisfies any WHERE clause )
    {
      foreach ( long id in idSet.All( ee ) ) if ( TE.Get( id, tr, Used ) )
      {
        if ( Where == null || Where.Eval( ee ).B )
        {
          for ( int i = 0; i < Exps.Count; i += 1 ) outrow[ i ] = Exps[ i ].Eval( ee );   
          if ( !srs.NewRow( outrow ) ) break;
        }
      }
    }
    else 
    // Fetch every record in source table, send it to output ( if it satisfies any WHERE clause )
    {
      foreach ( bool ok in TE.GetAll( tr, Used, ee ) )
      if ( Where == null || Where.Eval( ee ).B )
      {
        for ( int i = 0; i < Exps.Count; i += 1 ) outrow[ i ] = Exps[ i ].Eval( ee );   
        if ( !srs.NewRow( outrow ) ) break;
      }
    }
    srs.EndTable();
  }
Example #2
0
  public override G.IEnumerable<bool> GetAll( Value[] final, bool [] used, EvalEnv e )
  {
    Value[] tr = new Value[ TE.Cols.Count ];
    EvalEnv ee = new EvalEnv( e.Locals, tr, e.ResultSet );

    IdSet idSet = Where == null ? null : Where.GetIdSet( TE, ee );
    if ( idSet != null ) idSet = new IdCopy( idSet, ee ); // Need to take a copy of the id values if an index is used.

    StoredResultSet srs = Order == null ? null : new Sorter( null, SortSpec );
    srs = GroupSpec == null ? srs : new Grouper( srs, GroupSpec, AggSpec );

    Value [] outrow = srs != null ? new Value[ Exps.Count ] : null;

    if ( srs == null )
    {
      if ( idSet != null ) 
      {
        foreach ( long id in idSet.All( ee ) ) if ( TE.Get( id, tr, Used ) )
        {
          if ( Where == null || ( Where.Eval( ee ).B ) )
          {
            for ( int i = 0; i < final.Length; i += 1 ) final[ i ] = Exps[ i ].Eval( ee );  
            yield return true;
          }
        }
      }
      else 
      {
        foreach ( bool ok in TE.GetAll( tr, Used, ee ) )
        if ( Where == null || ( Where.Eval( ee ).B ) )
        {
          for ( int i = 0; i < final.Length; i += 1 ) final[ i ] = Exps[ i ].Eval( ee );  
          yield return true;
        }
      }
    }
    else
    {
      if ( idSet != null ) 
      {
        foreach ( long id in idSet.All( ee ) ) if ( TE.Get( id, tr, Used ) )
        {
          if ( Where == null || Where.Eval( ee ).B )
          {
            for ( int i = 0; i < Exps.Count; i += 1 ) outrow[ i ] = Exps[ i ].Eval( ee );  
            srs.NewRow( outrow ); 
          }
        }
      }
      else 
      {
        foreach ( bool ok in TE.GetAll( tr, Used, ee ) )
        if ( Where == null || Where.Eval( ee ).B )
        {
          for ( int i = 0; i < Exps.Count; i += 1 ) outrow[ i ] = Exps[ i ].Eval( ee );  
          srs.NewRow( outrow ); 
        }
      }
      foreach( bool b in srs.GetAll( final ) ) yield return true;
    }
  }