Exemplo n.º 1
0
 private void InsertResult(Session session, IPersistentStore store, RowSetNavigatorData nav, SqlType[] fromDataTypes, SqlType[] toDataTypes)
 {
     while (nav.HasNext())
     {
         object[] next = nav.GetNext();
         for (int i = 0; i < next.Length; i++)
         {
             if (fromDataTypes[i].TypeCode != toDataTypes[i].TypeCode)
             {
                 next[i] = fromDataTypes[i].ConvertToType(session, next[i], toDataTypes[i]);
             }
         }
         base._table.InsertData(session, store, next);
     }
 }
Exemplo n.º 2
0
 public override void Materialise(Session session)
 {
     if (!this._matrializationOnProgress)
     {
         if (this.RecursiveQueryExpression == null)
         {
             base.Materialise(session);
         }
         else
         {
             this._matrializationOnProgress = true;
             IRangeIterator[]    iteratorArray    = (IRangeIterator[])session.sessionContext.RangeIterators.Clone();
             RowSetNavigatorData navigator        = (RowSetNavigatorData)this.AnchorQueryExpression.GetResult(session, 0).GetNavigator();
             IPersistentStore    subqueryRowStore = session.sessionData.GetSubqueryRowStore(base._table);
             base._table.ClearAllData(subqueryRowStore);
             base._table.InsertFromNavigator(session, subqueryRowStore, navigator);
             int       num           = 0;
             SqlType[] columnTypes   = this.AnchorQueryExpression.GetColumnTypes();
             SqlType[] fromDataTypes = this.RecursiveQueryExpression.GetColumnTypes();
             while (num++ < 0x2710)
             {
                 RowSetNavigatorData other = (RowSetNavigatorData)this.RecursiveQueryExpression.GetResult(session, 0).GetNavigator();
                 if (other.GetSize() == 0)
                 {
                     other.Close();
                     break;
                 }
                 int size      = navigator.GetSize();
                 int unionType = this.UnionType;
                 if (unionType == 1)
                 {
                     navigator.Union(other);
                 }
                 else
                 {
                     if (unionType != 2)
                     {
                         throw Error.RuntimeError(0xc9, "QueryExpression");
                     }
                     navigator.UnionAll(other);
                 }
                 base._table.ClearAllData(subqueryRowStore);
                 other.BeforeFirst();
                 this.InsertResult(session, subqueryRowStore, other, fromDataTypes, columnTypes);
                 other.Close();
                 if (size == navigator.GetSize())
                 {
                     break;
                 }
             }
             session.sessionContext.RangeIterators = iteratorArray;
             if (base._uniqueRows)
             {
                 navigator.RemoveDuplicates();
             }
             base._table.ClearAllData(subqueryRowStore);
             this.InsertResult(session, subqueryRowStore, navigator, fromDataTypes, this.UnionDataTypes);
             navigator.Close();
             this._matrializationOnProgress = false;
         }
     }
 }
Exemplo n.º 3
0
        public virtual Result GetResult(Session session, int maxRows)
        {
            int    num    = (this._unionType == 2) ? maxRows : 0;
            Result result = this._leftQueryExpression.GetResult(session, num);
            RowSetNavigatorData navigator = (RowSetNavigatorData)result.GetNavigator();
            RowSetNavigatorData other     = (RowSetNavigatorData)this._rightQueryExpression.GetResult(session, num).GetNavigator();

            if (this._unionCorresponding)
            {
                bool flag1 = (session.ResultMaxMemoryRows == 0) || ((navigator.GetSize() < session.ResultMaxMemoryRows) && (other.GetSize() < session.ResultMaxMemoryRows));
                RowSetNavigatorData data1 = flag1 ? new RowSetNavigatorData(session, this) : new RowSetNavigatorDataTable(session, this);
                data1.Copy(navigator, this._leftQueryExpression.UnionColumnMap);
                navigator = data1;
                result.SetNavigator(navigator);
                result.MetaData = this.GetMetaData();
                RowSetNavigatorData data3 = flag1 ? new RowSetNavigatorData(session, this) : new RowSetNavigatorDataTable(session, this);
                data3.Copy(other, this._rightQueryExpression.UnionColumnMap);
                other = data3;
                navigator.Reset();
                other.Reset();
            }
            switch (this._unionType)
            {
            case 1:
                navigator.Union(other);
                break;

            case 2:
                navigator.UnionAll(other);
                break;

            case 3:
                navigator.Intersect(other);
                break;

            case 4:
                navigator.IntersectAll(other);
                break;

            case 5:
                navigator.ExceptAll(other);
                break;

            case 6:
                navigator.Except(other);
                break;

            default:
                throw Error.RuntimeError(0xc9, "QueryExpression");
            }
            if (this.ExprSortAndSlice.HasOrder())
            {
                navigator.SortUnion(this.ExprSortAndSlice);
            }
            if (this.ExprSortAndSlice.HasLimit())
            {
                navigator.Trim(this.ExprSortAndSlice.GetLimitStart(session), this.ExprSortAndSlice.GetLimitCount(session, maxRows));
            }
            navigator.Reset();
            return(result);
        }