Ejemplo n.º 1
0
        private void Stack(Program program, Database db, Order order, Order key, TableNode node)
        {
            _key = key;

            OrderColumn column = order.Columns[order.Columns.Count - 1];

            _direction = column.Ascending ? ScanDirection.Forward : ScanDirection.Backward;

            _order = new Order();
            _order.Columns.Add(column);

            _nestedOrder = new Order();
            for (int i = 0; i < order.Columns.Count - 1; i++)
            {
                _nestedOrder.Columns.Add(order.Columns[i]);
            }

            _nestedComparer = new RowComparer(_nestedOrder.Columns[_nestedOrder.Columns.Count - 1], Program.ValueManager);
            _comparer       = new RowComparer(_order.Columns[0], Program.ValueManager);

            if (_nestedOrder.Columns.Count == 1)
            {
                FastoreCursor scan = new FastoreCursor(program, db, node);
                scan.Key        = key;
                scan.Direction  = _nestedOrder.Columns[0].Ascending ? ScanDirection.Forward : ScanDirection.Backward;
                scan.Node.Order = _nestedOrder;
                _nestedTable    = scan;
            }
            else
            {
                _nestedTable = new FastoreStackedCursor(program, db, _nestedOrder, key, node);
            }
        }
Ejemplo n.º 2
0
 //Execute is what actually returns a value? Plan is executed which return a scan.
 protected override object InternalExecute(Program program, PlanNode planNode)
 {
     if (planNode is BaseTableVarNode)
     {
         FastoreCursor scan = new FastoreCursor(program, _db, (BaseTableVarNode)planNode);
         try
         {
             scan.Open();
             return(scan);
         }
         catch
         {
             scan.Dispose();
             throw;
         }
     }
     else if (planNode is OrderNode)
     {
         OrderNode orderNode = (OrderNode)planNode;
         if (orderNode.Order.Columns.Count == 1)
         {
             FastoreCursor scan = new FastoreCursor(program, _db, (BaseTableVarNode)planNode.Nodes[0]);
             try
             {
                 scan.Key        = orderNode.PhysicalOrder;
                 scan.Direction  = orderNode.ScanDirection;
                 scan.Node.Order = orderNode.Order;
                 scan.Open();
                 return(scan);
             }
             catch
             {
                 scan.Dispose();
                 throw;
             }
         }
         else
         {
             FastoreStackedCursor scan = new FastoreStackedCursor(program, _db, orderNode.Order, orderNode.PhysicalOrder, (BaseTableVarNode)planNode.Nodes[0]);
             try
             {
                 scan.Open();
                 return(scan);
             }
             catch
             {
                 scan.Dispose();
                 throw;
             }
         }
     }
     else if (planNode is CreateTableVarBaseNode)
     {
         EnsureFastoreTable(((CreateTableVarBaseNode)planNode).GetTableVar());
         return(null);
     }
     else if (planNode is AlterTableNode)
     {
         // TODO: Memory device alter table support
         return(null);
     }
     else if (planNode is DropTableNode)
     {
         Schema.TableVar tableVar = ((DropTableNode)planNode).Table;
         FastoreTables   tables   = GetTables(tableVar.Scope);
         lock (tables)
         {
             int tableIndex = tables.IndexOf(tableVar);
             if (tableIndex >= 0)
             {
                 FastoreTable nativeTable = tables[tableIndex];
                 nativeTable.Drop(program.ValueManager);
                 tables.RemoveAt(tableIndex);
             }
         }
         return(null);
     }
     else
     {
         throw new DeviceException(DeviceException.Codes.InvalidExecuteRequest, Device.Name, planNode.ToString());
     }
 }