Beispiel #1
0
 public static Bamboo.DataStructures.Table Evaluate(Database database, object statement)
 {
     if (statement is SelectStatement)
     {
         Iterators.Iterator iterator = CreateIterator(database, (SelectStatement)statement);
         if (iterator == null)
         {
             return(null);
         }
         return(iterator.ToTable());
     }
     else if (statement is UnionStatement)
     {
         Iterators.Iterator iterator = CreateIterator(database, (UnionStatement)statement);
         if (iterator == null)
         {
             return(null);
         }
         return(iterator.ToTable());
     }
     else
     {
         throw new System.Exception("Invalid statement.");
     }
 }
Beispiel #2
0
        private static Predicates.Predicate CreatePredicate(Predicate predicate, Iterators.Iterator iterator)
        {
            switch (predicate.Operator.ToUpper())
            {
            case "AND":
            {
                return(new Predicates.AndPredicate(CreatePredicate((Predicate)predicate.A, iterator), CreatePredicate((Predicate)predicate.B, iterator)));
            }

            case "=":
            {
                return(new Predicates.EqualsPredicate(GetOrdinal(predicate.A, iterator.Columns()), predicate.B));
            }

            case "!=":
            case "<>":
            {
                return(new Predicates.NotEqualsPredicate(GetOrdinal(predicate.A, iterator.Columns()), predicate.B));
            }

            case "NOT":
            {
                return(new Predicates.NotPredicate(CreatePredicate((Predicate)predicate.A, iterator)));
            }

            case "OR":
            {
                return(new Predicates.OrPredicate(CreatePredicate((Predicate)predicate.A, iterator), CreatePredicate((Predicate)predicate.B, iterator)));
            }

            default:
            {
                throw new System.Exception("Invalid predicate: " + predicate.Operator);
            }
            }
        }
Beispiel #3
0
        private static Iterators.ColumnIterator CreateColumnIterator(object column, Iterators.Iterator iterator)
        {
            if (column is Identifier)
            {
                return(new Iterators.ColumnIterator(GetOrdinal(column, iterator.Columns()), ((Identifier)column).Value));
            }
            else if (column is Alias)
            {
                Alias alias = (Alias)column;
                return(new Iterators.AliasIterator(CreateColumnIterator(alias.Name, iterator), alias.As.Value));
            }
            else if (column is Function)
            {
                Function function = (Function)column;
                System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                stringBuilder.Append(function.Name);
                stringBuilder.Append("(");
                for (int i = 0; i < function.Operands.Count; i++)
                {
                    if (i > 0)
                    {
                        stringBuilder.Append(", ");
                    }
                    stringBuilder.Append(function.Operands[i].ToString());
                }
                stringBuilder.Append(")");

                Functions.Function fn = Functions.Function.Create(function.Name.Value, cdr(function.Operands));

                return(new Iterators.FunctionIterator(GetOrdinal(function.Operands[0], iterator.Columns()), stringBuilder.ToString(), fn));
            }
            else
            {
                throw new System.Exception();
            }
        }