public override CommandData CreateSelectInsertCommand(InsertSelector insertSelector, DataEntityMapping mapping,
                                                              AggregateSelector selector, AggregateGroupBy groupBy, QueryExpression query, QueryExpression having,
                                                              OrderExpression order, CreateSqlState state)
        {
            var selectCommandData =
                CreateAggregateTableCommand(mapping, selector, groupBy, query, having, null, null, state);
            var insertFields     = insertSelector.GetInsertFields();
            var insertFieldNames = new string[insertFields.Length];

            for (var i = 0; i < insertFields.Length; i++)
            {
                insertFieldNames[i] = CreateDataFieldSql(insertFields[i].FieldName);
            }

            var insertString = string.Join(",", insertFieldNames);
            var selectString = insertSelector.CreateSelectString(this, false, state);
            var sql          =
                $"insert into {CreateDataTableMappingSql(insertSelector.InsertMapping, state)}({insertString})select {selectString} from ({selectCommandData.CommandText}) as A";

            if (order != null)
            {
                state.UseFieldAlias = true;
                sql += GetOrderString(order, false, state);
                state.UseFieldAlias = false;
            }

            selectCommandData.CommandText = sql;
            return(selectCommandData);
        }
Exemple #2
0
        private void DoInsertNextRecursion(ref InsertSelector insertSelector, ref THandler next, XPipelineContext <THandler> current)
        {
            if (insertSelector(current.Handler))
            {
                var next_context = new XPipelineContext <THandler>(next);
                var origin_next  = current.Next;
                current.Next      = next_context;
                next_context.Prev = current;
                next_context.Next = origin_next;

                if (origin_next != null)
                {
                    origin_next.Prev = next_context;
                }

                if (_last == current)
                {
                    _last = next_context;
                }
            }
            else if (current.Next != null)
            {
                DoInsertNextRecursion(ref insertSelector, ref next, current.Next);
            }
        }
Exemple #3
0
        public void InsertNext(InsertSelector insertSelector, THandler next)
        {
            if (insertSelector == null)
            {
                throw new ArgumentNullException(nameof(insertSelector));
            }
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (_head != null)
            {
                DoInsertNextRecursion(ref insertSelector, ref next, _head);
            }
        }