コード例 #1
0
ファイル: QueryVisitor.cs プロジェクト: sharkAndshark/linq2db
 void VisitX(SqlGroupByClause element)
 {
     foreach (var i in element.Items)
     {
         Visit(i);
     }
 }
コード例 #2
0
ファイル: SqlGroupByClause.cs プロジェクト: kidkai25/linq2db
 internal SqlGroupByClause(
     SelectQuery selectQuery,
     SqlGroupByClause clone,
     Dictionary <ICloneableElement, ICloneableElement> objectTree,
     Predicate <ICloneableElement> doClone)
     : base(selectQuery)
 {
     Items.AddRange(clone.Items.Select(e => (ISqlExpression)e.Clone(objectTree, doClone)));
 }
コード例 #3
0
ファイル: CloneVisitor.cs プロジェクト: sharkAndshark/linq2db
        private SqlGroupByClause Clone(SelectQuery selectQuery, SqlGroupByClause groupBy)
        {
            var newGroupBy = new SqlGroupByClause(selectQuery)
            {
                GroupingType = groupBy.GroupingType
            };

            CloneInto(newGroupBy.Items, groupBy.Items);
            return(newGroupBy);
        }
コード例 #4
0
        public SelectQuery()
        {
            SourceID = Interlocked.Increment(ref SourceIDCounter);

            Select  = new SqlSelectClause(this);
            From    = new SqlFromClause(this);
            Where   = new SqlWhereClause(this);
            GroupBy = new SqlGroupByClause(this);
            Having  = new SqlWhereClause(this);
            OrderBy = new SqlOrderByClause(this);
        }
コード例 #5
0
ファイル: SelectQuery.cs プロジェクト: stsrki/linq2db
        SelectQuery(SelectQuery clone, Dictionary <ICloneableElement, ICloneableElement> objectTree, Predicate <ICloneableElement> doClone)
        {
            objectTree.Add(clone, this);
            objectTree.Add(clone.All, All);

            SourceID = Interlocked.Increment(ref SourceIDCounter);

            ICloneableElement parentClone;

            if (clone.ParentSelect != null)
            {
                ParentSelect = objectTree.TryGetValue(clone.ParentSelect, out parentClone) ? (SelectQuery)parentClone : clone.ParentSelect;
            }

            _queryType = clone._queryType;

            if (IsInsert)
            {
                _insert = (SqlInsertClause)clone._insert.Clone(objectTree, doClone);
            }
            if (IsUpdate)
            {
                _update = (SqlUpdateClause)clone._update.Clone(objectTree, doClone);
            }
            if (IsDelete)
            {
                _delete = (SqlDeleteClause)clone._delete.Clone(objectTree, doClone);
            }

            Select   = new SqlSelectClause(this, clone.Select, objectTree, doClone);
            _from    = new SqlFromClause(this, clone._from, objectTree, doClone);
            _where   = new SqlWhereClause(this, clone._where, objectTree, doClone);
            _groupBy = new SqlGroupByClause(this, clone._groupBy, objectTree, doClone);
            _having  = new SqlWhereClause(this, clone._having, objectTree, doClone);
            _orderBy = new SqlOrderByClause(this, clone._orderBy, objectTree, doClone);

            Parameters.AddRange(clone.Parameters.Select(p => (SqlParameter)p.Clone(objectTree, doClone)));
            IsParameterDependent = clone.IsParameterDependent;

            new QueryVisitor().Visit(this, expr =>
            {
                var sb = expr as SelectQuery;

                if (sb != null && sb.ParentSelect == clone)
                {
                    sb.ParentSelect = this;
                }
            });
        }
コード例 #6
0
        internal void Init(
            SqlSelectClause select,
            SqlFromClause from,
            SqlWhereClause where,
            SqlGroupByClause groupBy,
            SqlWhereClause having,
            SqlOrderByClause orderBy,
            List <SqlSetOperator>?setOperators,
            List <ISqlExpression[]>?uniqueKeys,
            SelectQuery?parentSelect,
            bool parameterDependent,
            string?queryName,
            bool doNotSetAliases)
        {
            Select               = select;
            From                 = from;
            Where                = where;
            GroupBy              = groupBy;
            Having               = having;
            OrderBy              = orderBy;
            _setOperators        = setOperators;
            ParentSelect         = parentSelect;
            IsParameterDependent = parameterDependent;
            QueryName            = queryName;
            DoNotSetAliases      = doNotSetAliases;

            if (uniqueKeys != null)
            {
                UniqueKeys.AddRange(uniqueKeys);
            }

            foreach (var col in select.Columns)
            {
                col.Parent = this;
            }

            Select.SetSqlQuery(this);
            From.SetSqlQuery(this);
            Where.SetSqlQuery(this);
            GroupBy.SetSqlQuery(this);
            Having.SetSqlQuery(this);
            OrderBy.SetSqlQuery(this);
        }
コード例 #7
0
ファイル: SelectQuery.cs プロジェクト: stsrki/linq2db
        internal void Init(
            SqlInsertClause insert,
            SqlUpdateClause update,
            SqlDeleteClause delete,
            SqlSelectClause select,
            SqlFromClause from,
            SqlWhereClause where,
            SqlGroupByClause groupBy,
            SqlWhereClause having,
            SqlOrderByClause orderBy,
            List <SqlUnion> unions,
            SelectQuery parentSelect,
            bool parameterDependent,
            List <SqlParameter> parameters)
        {
            _insert              = insert;
            _update              = update;
            _delete              = delete;
            Select               = select;
            _from                = from;
            _where               = where;
            _groupBy             = groupBy;
            _having              = having;
            _orderBy             = orderBy;
            _unions              = unions;
            ParentSelect         = parentSelect;
            IsParameterDependent = parameterDependent;

            Parameters.AddRange(parameters);

            foreach (var col in select.Columns)
            {
                col.Parent = this;
            }

            Select.SetSqlQuery(this);
            _from.SetSqlQuery(this);
            _where.SetSqlQuery(this);
            _groupBy.SetSqlQuery(this);
            _having.SetSqlQuery(this);
            _orderBy.SetSqlQuery(this);
        }
コード例 #8
0
        SelectQuery(SelectQuery clone, Dictionary <ICloneableElement, ICloneableElement> objectTree, Predicate <ICloneableElement> doClone)
        {
            objectTree.Add(clone, this);
            objectTree.Add(clone.All, All);

            SourceID = Interlocked.Increment(ref SourceIDCounter);

            if (clone.ParentSelect != null)
            {
                ParentSelect = objectTree.TryGetValue(clone.ParentSelect, out var parentClone) ? (SelectQuery)parentClone : clone.ParentSelect;
            }

            Select  = new SqlSelectClause(this, clone.Select, objectTree, doClone);
            From    = new SqlFromClause(this, clone.From, objectTree, doClone);
            Where   = new SqlWhereClause(this, clone.Where, objectTree, doClone);
            GroupBy = new SqlGroupByClause(this, clone.GroupBy, objectTree, doClone);
            Having  = new SqlWhereClause(this, clone.Having, objectTree, doClone);
            OrderBy = new SqlOrderByClause(this, clone.OrderBy, objectTree, doClone);

            if (clone.HasSetOperators)
            {
                SetOperators.AddRange(
                    clone.SetOperators.Select(u =>
                                              new SqlSetOperator((SelectQuery)u.SelectQuery.Clone(objectTree, doClone), u.Operation)));
            }

            IsParameterDependent = clone.IsParameterDependent;

            if (clone.HasUniqueKeys)
            {
                UniqueKeys.AddRange(clone.UniqueKeys.Select(uk => uk.Select(e => (ISqlExpression)e.Clone(objectTree, doClone)).ToArray()));
            }

            new QueryVisitor().Visit(this, expr =>
            {
                if (expr is SelectQuery sb && sb.ParentSelect == clone)
                {
                    sb.ParentSelect = this;
                }
            });