Ejemplo n.º 1
0
 static string DoConcat( DS[] dlist, EvalEnv e )
 {
   string [] slist = new string[ dlist.Length ];
   for ( int i = 0; i < dlist.Length; i += 1 )
     slist[ i ] = dlist[ i ]( e );
   return string.Join( null, slist );
 }
        public override Value Eval(EvalEnv e)
        {
            Value result = new Value();

            result.L = e.ResultSet.LastIdInserted;
            return(result);
        }
        public override Value Eval(EvalEnv e)
        {
            Value  s     = Arg[0].Eval(e);
            string x     = (string)s._O;
            int    start = (int)Arg[1].Eval(e).L - 1;
            int    len   = (int)Arg[2].Eval(e).L;

            if (start < 0)
            {
                start = 0;
            }
            if (start > x.Length)
            {
                start = x.Length;
            }
            if (len < 0)
            {
                len = 0;    // Maybe should raise exception
            }
            if (len > x.Length - start)
            {
                len = x.Length - start;
            }

            s.O = ((string)s._O).Substring(start, len);

            return(s);
        }
        public Value ExecuteFunctionCall(EvalEnv e, Exp [] parms)
        {
            // Allocate the local variables for the called function.
            var locals = new Value[LocalType.Count];

            // Evaluate the parameters to be passed, saving them in the newly allocated local variables.
            for (int i = 0; i < parms.Length; i += 1)
            {
                locals[i] = parms[i].Eval(e);
            }

            // Save local state.
            var save1 = Locals;
            var save2 = NextStatement;

            // Execute the function
            Locals = locals;

            ExecuteStatements(e.ResultSet);

            // Restore local state.
            NextStatement = save2;
            Locals        = save1;

            return(FunctionResult);
        }
Ejemplo n.º 5
0
 public override G.IEnumerable<Value> Values( EvalEnv ee )
 {
   for ( int i = 0; i < List.Length; i += 1 )
   {
     yield return List[i].Eval( ee );
   }
 }
Ejemplo n.º 6
0
 public override Value Eval( EvalEnv e )
 {
   Value lhs = Lhs.Eval( e );
   Value result = new Value();
   result.B = Rhs.TestIn( lhs, e );
   return result;    
 }
Ejemplo n.º 7
0
  public override G.IEnumerable<bool> GetAll( Value[] final, int [] cols, EvalEnv e )
  {
    Value[] tr = new Value[ TE.CI.Count ];
    EvalEnv ee = new EvalEnv( e.Locals, tr, e.ResultSet );

    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 ( Ids != null ) 
      {
        foreach ( long id in Ids.All( ee ) ) if ( TE.Get( id, tr, Used ) )
        {
          if ( WhereD == null || WhereD( ee ) )
          {
            for ( int i = 0; i < final.Length; i += 1 ) final[ i ] = Dvs[ i ]( ee ); 
            yield return true;
          }
        }
      }
      else 
      {
        foreach ( bool ok in TE.GetAll( tr, Used, ee ) )
        if ( WhereD == null || WhereD( ee ) )
        {
          for ( int i = 0; i < final.Length; i += 1 ) final[ i ] = Dvs[ i ]( ee ); 
          yield return true;
        }
      }
    }
    else
    {
      if ( Ids != null ) 
      {
        foreach ( long id in Ids.All( ee ) ) if ( TE.Get( id, tr, Used ) )
        {
          if ( WhereD == null || WhereD( ee ) )
          {
            for ( int i = 0; i < Exps.Count; i += 1 ) outrow[ i ] = Dvs[ i ]( ee ); 
            srs.NewRow( outrow ); 
          }
        }
      }
      else 
      {
        foreach ( bool ok in TE.GetAll( tr, Used, ee ) )
        if ( WhereD == null || WhereD( ee ) )
        {
          for ( int i = 0; i < Exps.Count; i += 1 ) outrow[ i ] = Dvs[ i ]( ee );  
          srs.NewRow( outrow ); 
        }
      }

      foreach( bool b in srs.GetStoredRows( final ) ) yield return true;
    }
  }
Ejemplo n.º 8
0
 public override Value Eval( EvalEnv e ) 
 { 
   if ( Type <= DataType.String && e.Locals[I]._O == null )
   {
     e.Locals[I] = DTI.Default( Type );
   }
   return e.Locals[I]; 
 }
Ejemplo n.º 9
0
 public override G.IEnumerable<Value> Values( EvalEnv ee )
 {
   var rs = new SingleResultSet();
   TE.FetchTo( rs, ee  );
   var rows = rs.Table.Rows;
   for ( int i = 0; i < rows.Count; i += 1 )
     yield return rows[i][0];
 }
        public override Value Eval(EvalEnv e)
        {
            Value result = new Value();
            int   ix     = (int)Arg[0].Eval(e).L;

            result.O = e.ResultSet.FileContent(ix);
            return(result);
        }
        public override Value Eval(EvalEnv e)
        {
            object o      = E.Eval(e)._O;
            Value  result = new Value();

            result.L = SType == DataType.String ? ((string)o).Length : ((byte[])o).Length;
            return(result);
        }
        public override Value Eval(EvalEnv e)
        {
            Value  s   = Arg[0].Eval(e);
            string pat = (string)(Arg[1].Eval(e)._O);
            string sub = (string)(Arg[2].Eval(e)._O);

            s.O = ((string)s._O).Replace(pat, sub);
            return(s);
        }
        public override Value Eval(EvalEnv e)
        {
            Value result = new Value();
            var   ex     = e.ResultSet.Exception;

            result.O = ex == null ? "" : ex.ToString(); // .Message or .ToString() for full debug info.
            e.ResultSet.Exception = null;
            return(result);
        }
        public override Value Eval(EvalEnv e)
        {
            Value result = new Value();
            int   ix     = (int)Arg[0].Eval(e).L;
            int   kind   = (int)Arg[1].Eval(e).L;

            result.O = e.ResultSet.FileAttr(ix, kind);
            return(result);
        }
        public override Value Eval(EvalEnv e)
        {
            int    kind   = (int)Arg[0].Eval(e).L;
            string name   = (string)Arg[1].Eval(e)._O;
            Value  result = new Value();

            result.O = e.ResultSet.Arg(kind, name);
            return(result);
        }
Ejemplo n.º 16
0
 public override bool TestIn( Value x, EvalEnv e )
 {
   for ( int i=0; i < List.Length; i += 1 )
   {
     Value y = Dvs[ i ]( e );
     if ( Util.Equals( x, y, Type ) ) return true;
   }
   return false;
 }
Ejemplo n.º 17
0
 public override bool TestIn( Value x, EvalEnv e )
 {
   for ( int i=0; i < List.Length; i += 1 )
   {
     Value y = List[i].Eval( e );
     if ( Util.Equal( x, y, ElementType ) ) return true;
   }
   return false;
 }
Ejemplo n.º 18
0
 public override Value Eval( EvalEnv e )
 {
   for ( int i = 0; i < List.Length; i += 1 ) 
   {
     Exp test = List[i].Test;
     if ( test == null || test.Eval( e ).B ) return List[i].E.Eval( e );
   }
   return new Value(); // Should not get here.
 }
Ejemplo n.º 19
0
 public override Value Eval( EvalEnv e )
 {
   Value v = E.Eval( e );
   decimal d = v.L;
   int scale = DTI.Scale( E.Type );
   d = d / Util.PowerTen( scale );
   v.O = d.ToString( "F" + scale, System.Globalization.CultureInfo.InvariantCulture );
   return v;
 }  
Ejemplo n.º 20
0
        string GetException(EvalEnv ee)
        {
            var    ex     = ee.ResultSet.Exception;
            string result =
                ex == null ? ""
      : (ex is UserException || ex is Exception) ? ex.Message
      : ex.ToString(); // for full debug info.

            ee.ResultSet.Exception = null;
            return(result);
        }
Ejemplo n.º 21
0
 public override void FetchTo( ResultSet rs, EvalEnv ee )
 {
   Value [] row = new Value[ ColumnCount ];
   for ( int j = 0; j < Values.Count; j += 1 )
   {
     var e = Values[ j ];
     for ( int i=0; i < ColumnCount; i += 1 )
     {
       row[ i ] = e[ i ].GetDV()( ee );
     }
     if ( !rs.NewRow( row ) ) break;
   }
 }
        public override Value Eval(EvalEnv e)
        {
            string s = (string)Arg[0].Eval(e)._O;

            try
            {
                Value result = new Value();
                result.D = double.Parse(s);
                return(result);
            }
            catch (System.Exception)
            {
                throw new System.Exception("Error converting [" + s + "] to double");
            }
        }
        public override Value Eval(EvalEnv e)
        {
            string   s = (string)Arg[0].Eval(e)._O;
            DataType t = (DataType)Arg[1].Eval(e).L;

            try
            {
                Value result = new Value();
                result.L = (long)(decimal.Parse(s) * Util.PowerTen(DTI.Scale(t)));
                return(result);
            }
            catch (System.Exception)
            {
                throw new System.Exception("Error converting [" + s + "] to decimal");
            }
        }
Ejemplo n.º 24
0
 public override IdSet GetIdSet( TableExpression te, EvalEnv ee )
 {
   if ( Lhs is ExpName && Rhs.IsConstant() )
   {
     ExpName e = (ExpName)Lhs;
     if ( e.ColName == "Id" ) // select ... from t where id in ( .... )
     {
       return Rhs.ListIdSet( ee );
     }
     IndexFile ix = te.FindIndex( e.ColIx );
     if ( ix != null ) // select ... from t where indexedcol in ( .... )
     {        
       return new Lookup( ix, Rhs.Values( ee ) ); // For each value in the Rhs list, lookup it's ids, and return them in the IdSet.
     }
   }
   return null;
 }
Ejemplo n.º 25
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();
  }
Ejemplo n.º 26
0
        public Value ExecuteRoutine(EvalEnv e, Exp.DV [] parms)
        {
            // Allocate the local variables.
            var locals = InitLocals();

            // Evaluate the parameters to be passed, saving them in the newly allocated local variables.
            for (int i = 0; i < parms.Length; i += 1)
            {
                locals[i] = parms[i](e);
            }

            // Save local state.
            var save1 = Locals; var save2 = NextStatement;

            Locals = locals;

            if (IsFunc)
            {
                ExecuteStatements(e.ResultSet);
            }
            else
            {
                try
                {
                    ExecuteStatements(e.ResultSet);
                }
                catch (System.Exception exception)
                {
                    Db.SetRollback();
                    ResultSet.Exception = exception;
                }
            }

            // Restore local state.
            NextStatement = save2; Locals = save1;

            return(FunctionResult);
        }
Ejemplo n.º 27
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.CI.Count ];

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

    rs.NewTable( CI );

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

    if ( Ids != null ) 
    // Fetch subset of source table using id values, send to ResultSet (if it satisfies any WHERE clause )
    {
      foreach ( long id in Ids.All( ee ) ) if ( TE.Get( id, tr, Used ) )
      {
        if ( Where == null || WhereD( ee ) )
        {
          for ( int i = 0; i < Exps.Count; i += 1 ) outrow[ i ] = Dvs[ i ]( 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 || WhereD( ee ) )
      {
        for ( int i = 0; i < Exps.Count; i += 1 ) outrow[ i ] = Dvs[ i ]( ee );  
        if ( !srs.NewRow( outrow ) ) break;
      }
    }
    srs.EndTable();
  }
Ejemplo n.º 28
0
  public override IdSet GetIdSet( TableExpression te, EvalEnv ee )
  {
    if ( Operator <= Token.Equal && Right.IsConstant() && Left is ExpName )
    {
      ExpName e = ((ExpName)Left);
      if ( e.ColName == "Id" && Operator == Token.Equal ) return new SingleId( Right );
      IndexFile ix = te.FindIndex( e.ColIx );
      if ( ix != null ) 
      {
        // Console.WriteLine( "Index found " + ToString() );
        return new IndexFrom( ix, Right, Operator );
      }
    }
    else if ( Operator <= Token.Equal && Left.IsConstant() && Right is ExpName )
    {
      ExpName e = ((ExpName)Right);
      if ( e.ColName == "Id" && Operator == Token.Equal ) return new SingleId( Left );
      IndexFile ix = te.FindIndex( e.ColIx );
      if ( ix != null ) 
      {
        // Console.WriteLine( "Index found " + ToString() );
        return new IndexFrom( ix, Left, TokenInfo.Reflect( Operator ) );
      }
    }

    if ( Operator == Token.And )
    {
      var left = Left.GetIdSet( te, ee );
      if ( left != null ) return left;
      var right = Right.GetIdSet( te ,ee );
      if ( right != null ) return right;
    }

    // Console.WriteLine( "Index not found " + ToString() );
    return null;
  }
Ejemplo n.º 29
0
 public override Value Eval( EvalEnv e )
 { 
   return E.Eval( e );
 }
Ejemplo n.º 30
0
 public override IdSet ListIdSet( EvalEnv ee )
 {
   return new TableExpressionIdSet( TE, ee );
 }