コード例 #1
0
ファイル: Select.cs プロジェクト: nesrinesghaier/upa
 public virtual Net.Vpc.Upa.Expressions.Select AddQuery(Net.Vpc.Upa.Expressions.Select other)
 {
     if (other == null)
     {
         return(this);
     }
     if (other.queryEntity != null)
     {
         queryEntity = other.queryEntity;
     }
     if (other.queryEntityAlias != null)
     {
         queryEntityAlias = other.queryEntityAlias;
     }
     for (int i = 0; i < (other.joinsEntities).Count; i++)
     {
         Net.Vpc.Upa.Expressions.JoinCriteria j = other.GetJoin(i);
         Join(j.GetJoinType(), j.GetEntity(), j.GetEntityAlias(), j.GetCondition());
     }
     foreach (Net.Vpc.Upa.Expressions.QueryField field in other.fields)
     {
         fields.Add(new Net.Vpc.Upa.Expressions.QueryField(field.GetAlias(), field.GetExpression().Copy()));
     }
     order.AddOrder(other.order.Copy());
     group.AddGroup(other.group.Copy());
     this.where  = (other.where != null) ? other.where.Copy() : null;
     this.having = (other.having != null) ? other.having.Copy() : null;
     return(this);
 }
コード例 #2
0
ファイル: Select.cs プロジェクト: nesrinesghaier/upa
 public override System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.TaggedExpression> GetChildren()
 {
     System.Collections.Generic.IList <Net.Vpc.Upa.Expressions.TaggedExpression> list = new System.Collections.Generic.List <Net.Vpc.Upa.Expressions.TaggedExpression>();
     //    private Expression where;
     //    private Expression having;
     //    private Order order;
     if (queryEntity != null)
     {
         list.Add(new Net.Vpc.Upa.Expressions.TaggedExpression(queryEntity, ENTITY));
     }
     for (int i = 0; i < (fields).Count; i++)
     {
         list.Add(new Net.Vpc.Upa.Expressions.TaggedExpression(fields[i].GetExpression(), new Net.Vpc.Upa.Expressions.IndexedTag("FIELD", i)));
     }
     for (int i = 0; i < (joinsEntities).Count; i++)
     {
         Net.Vpc.Upa.Expressions.JoinCriteria get = joinsEntities[i];
         list.Add(new Net.Vpc.Upa.Expressions.TaggedExpression(get.GetEntity(), new Net.Vpc.Upa.Expressions.IndexedTag("JOIN_ENTITY", i)));
         list.Add(new Net.Vpc.Upa.Expressions.TaggedExpression(get.GetCondition(), new Net.Vpc.Upa.Expressions.IndexedTag("JOIN_COND", i)));
     }
     if (where != null)
     {
         list.Add(new Net.Vpc.Upa.Expressions.TaggedExpression(where, WEHRE));
     }
     for (int i = 0; i < group.Size(); i++)
     {
         Net.Vpc.Upa.Expressions.Expression ee = group.GetGroupAt(i);
         list.Add(new Net.Vpc.Upa.Expressions.TaggedExpression(ee, new Net.Vpc.Upa.Expressions.IndexedTag("GROUP", i)));
     }
     if (having != null)
     {
         list.Add(new Net.Vpc.Upa.Expressions.TaggedExpression(having, HAVING));
     }
     for (int i = 0; i < order.Size(); i++)
     {
         Net.Vpc.Upa.Expressions.Expression ee = order.GetOrderAt(i);
         list.Add(new Net.Vpc.Upa.Expressions.TaggedExpression(ee, new Net.Vpc.Upa.Expressions.IndexedTag("ORDER", i)));
     }
     return(list);
 }
コード例 #3
0
ファイル: Select.cs プロジェクト: nesrinesghaier/upa
        public override string ToString()
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder("Select ");
            if (top > 0)
            {
                sb.Append(" TOP ").Append(top);
            }
            if (distinct)
            {
                sb.Append(" DISTINCT");
            }
            sb.Append(" ");
            string aliasString = null;
            string valueString = null;
            bool   started     = false;

            if (CountFields() == 0)
            {
                sb.Append("...");
            }
            else
            {
                for (int i = 0; i < CountFields(); i++)
                {
                    Net.Vpc.Upa.Expressions.QueryField fi = GetField(i);
                    Net.Vpc.Upa.Expressions.Expression e  = fi.GetExpression();
                    valueString = System.Convert.ToString(e);
                    aliasString = fi.GetAlias();
                    if (started)
                    {
                        sb.Append(",");
                    }
                    else
                    {
                        started = true;
                    }
                    if (aliasString == null)
                    {
                        sb.Append(valueString);
                    }
                    else
                    {
                        sb.Append(valueString);
                        sb.Append(" ");
                        sb.Append(Net.Vpc.Upa.Expressions.ExpressionHelper.EscapeIdentifier(aliasString));
                    }
                }
            }
            if (GetEntity() == null)
            {
            }
            else
            {
                sb.Append(" From ");
                if (GetEntity() is Net.Vpc.Upa.Expressions.Select)
                {
                    sb.Append(GetEntity().ToString());
                }
                else
                {
                    Net.Vpc.Upa.Expressions.EntityName entityName = (Net.Vpc.Upa.Expressions.EntityName)GetEntity();
                    sb.Append(entityName);
                }
            }
            if (GetEntityAlias() != null)
            {
                sb.Append(" ").Append(Net.Vpc.Upa.Expressions.ExpressionHelper.EscapeIdentifier(GetEntityAlias()));
            }
            for (int i = 0; i < CountJoins(); i++)
            {
                Net.Vpc.Upa.Expressions.JoinCriteria e = GetJoin(i);
                sb.Append(" ").Append(e);
            }
            Net.Vpc.Upa.Expressions.Expression c = GetWhere();
            if (c != null && c.IsValid())
            {
                sb.Append(" Where ").Append(c);
            }
            if (CountGroupByItems() > 0)
            {
                sb.Append(" ");
                int maxGroups = CountGroupByItems();
                sb.Append("Group By ");
                for (int i = 0; i < maxGroups; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(GetGroupBy(i));
                }
            }
            int maxOrders = CountOrderByItems();

            if (maxOrders > 0)
            {
                sb.Append(" ");
                sb.Append("Order By ");
                for (int i = 0; i < maxOrders; i++)
                {
                    if (i > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(GetOrderBy(i));
                    if (IsOrderAscending(i))
                    {
                        sb.Append(" Asc ");
                    }
                    else
                    {
                        sb.Append(" Desc ");
                    }
                }
            }
            return(sb.ToString());
        }
コード例 #4
0
ファイル: Select.cs プロジェクト: nesrinesghaier/upa
 public virtual Net.Vpc.Upa.Expressions.Select Join(Net.Vpc.Upa.Expressions.JoinCriteria someJoin)
 {
     Join(someJoin.GetJoinType(), someJoin.GetEntity(), someJoin.GetEntityAlias(), someJoin.GetCondition());
     return(this);
 }
コード例 #5
0
        protected internal virtual Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect CompileSelect(Net.Vpc.Upa.Expressions.Select v, Net.Vpc.Upa.Impl.Uql.ExpressionTranslationManager manager, Net.Vpc.Upa.Impl.Uql.ExpressionDeclarationList declarations)
        {
            if (v == null)
            {
                return(null);
            }
            Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect s = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledSelect();
            s.SetDistinct(v.IsDistinct());
            s.SetTop(v.GetTop());
            Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect nameOrSelect = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)manager.TranslateAny(v.GetEntity(), declarations);
            string entityAlias = v.GetEntityAlias();

            System.Collections.Generic.HashSet <string> aliases = new System.Collections.Generic.HashSet <string>();
            if (entityAlias == null)
            {
                if (nameOrSelect is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)
                {
                    entityAlias = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)nameOrSelect).GetName();
                }
                else
                {
                    entityAlias = "ALIAS";
                }
                int i = 0;
                while (true)
                {
                    string a2 = i == 0 ? entityAlias : (entityAlias + i);
                    if (!aliases.Contains(a2))
                    {
                        aliases.Add(a2);
                        entityAlias = a2;
                        break;
                    }
                    i++;
                }
            }
            s.From(nameOrSelect, entityAlias);
            for (int i = 0; i < v.CountJoins(); i++)
            {
                Net.Vpc.Upa.Expressions.JoinCriteria c = v.GetJoin(i);
                Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect jnameOrSelect = (Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledNameOrSelect)manager.TranslateAny(c.GetEntity(), declarations);
                entityAlias = c.GetEntityAlias();
                if (entityAlias == null)
                {
                    if (nameOrSelect is Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)
                    {
                        entityAlias = ((Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledEntityName)nameOrSelect).GetName();
                    }
                    else
                    {
                        entityAlias = "ALIAS";
                    }
                    i = 0;
                    while (true)
                    {
                        string a2 = i == 0 ? entityAlias : (entityAlias + i);
                        if (!aliases.Contains(a2))
                        {
                            aliases.Add(a2);
                            entityAlias = a2;
                            break;
                        }
                        i++;
                    }
                }
                Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria cc = new Net.Vpc.Upa.Impl.Uql.Compiledexpression.CompiledJoinCriteria(c.GetJoinType(), jnameOrSelect, entityAlias, manager.TranslateAny(c.GetCondition(), declarations));
                s.Join(cc);
            }
            for (int i = 0; i < v.CountFields(); i++)
            {
                Net.Vpc.Upa.Expressions.QueryField field = v.GetField(i);
                s.Field(manager.TranslateAny(field.GetExpression(), declarations), field.GetAlias());
            }
            s.Where(manager.TranslateAny(v.GetWhere(), declarations));
            s.Having(manager.TranslateAny(v.GetHaving(), declarations));
            for (int i = 0; i < v.CountGroupByItems(); i++)
            {
                Net.Vpc.Upa.Expressions.Expression c = v.GetGroupBy(i);
                s.GroupBy(manager.TranslateAny(c, declarations));
            }
            for (int i = 0; i < v.CountOrderByItems(); i++)
            {
                Net.Vpc.Upa.Expressions.Expression c = v.GetOrderBy(i);
                s.OrderBy(manager.TranslateAny(c, declarations), v.IsOrderAscending(i));
            }
            return(s);
        }