public static int UpdateTable(this IQuery context, ObjectName tableName, IQueryPlanNode queryPlan,
                                      IEnumerable <SqlAssignExpression> assignments, int limit)
        {
            var columnNames = assignments.Select(x => x.ReferenceExpression)
                              .Cast <SqlReferenceExpression>()
                              .Select(x => x.ReferenceName.Name).ToArray();

            if (!context.UserCanUpdateTable(tableName, columnNames))
            {
                throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Update);
            }

            if (!context.UserCanSelectFromPlan(queryPlan))
            {
                throw new InvalidOperationException();
            }

            var table = context.GetMutableTable(tableName);

            if (table == null)
            {
                throw new ObjectNotFoundException(tableName);
            }

            var updateSet = queryPlan.Evaluate(context);

            return(table.Update(context, updateSet, assignments, limit));
        }
Ejemplo n.º 2
0
        public ITable Evaluate(IRequest context)
        {
            IQueryPlanNode node = CreateChildNode(context);
            var            t    = node.Evaluate(context);

            return(AliasName != null ? new ReferenceTable(t, AliasName) : t);
        }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public virtual ITable Evaluate(IQueryContext context)
        {
            // Create the view child node
            IQueryPlanNode node = CreateViewChildNode(context);
            // Evaluate the plan
            ITable t = node.Evaluate(context);

            return(aliasName != null ? new ReferenceTable((Table)t, aliasName) : t);
        }
Ejemplo n.º 4
0
        public static void DefineView(this IQuery context, ObjectName viewName, IQueryPlanNode queryPlan, bool replaceIfExists)
        {
            // We have to execute the plan to get the TableInfo that represents the
            // result of the view execution.
            var table = queryPlan.Evaluate(context);
            var tableInfo = table.TableInfo.Alias(viewName);

            var viewInfo = new ViewInfo(tableInfo, null, queryPlan);
            context.DefineView(viewInfo, replaceIfExists);
        }
Ejemplo n.º 5
0
        public static void DefineView(this IQuery context, ObjectName viewName, IQueryPlanNode queryPlan, bool replaceIfExists)
        {
            // We have to execute the plan to get the TableInfo that represents the
            // result of the view execution.
            var table     = queryPlan.Evaluate(context);
            var tableInfo = table.TableInfo.Alias(viewName);

            var viewInfo = new ViewInfo(tableInfo, null, queryPlan);

            context.DefineView(viewInfo, replaceIfExists);
        }
        public static int UpdateTable(this IQuery context, ObjectName tableName, IQueryPlanNode queryPlan,
			IEnumerable<SqlAssignExpression> assignments, int limit)
        {
            var columnNames = assignments.Select(x => x.ReferenceExpression)
                .Cast<SqlReferenceExpression>()
                .Select(x => x.ReferenceName.Name).ToArray();

            if (!context.UserCanUpdateTable(tableName, columnNames))
                throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Update);

            if (!context.UserCanSelectFromPlan(queryPlan))
                throw new InvalidOperationException();

            var table = context.GetMutableTable(tableName);
            if (table == null)
                throw new ObjectNotFoundException(tableName);

            var updateSet = queryPlan.Evaluate(context);
            return table.Update(context, updateSet, assignments, limit);
        }
Ejemplo n.º 7
0
        protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context)
        {
            var op = Operator;

            if (ob2.DataType is QueryType)
            {
                // The sub-query plan
                IQueryPlanNode plan = (IQueryPlanNode)ob2.Value;
                // Discover the correlated variables for this plan.
                IList <CorrelatedVariable> list = plan.DiscoverCorrelatedVariables(1, new List <CorrelatedVariable>());

                if (list.Count > 0)
                {
                    // Set the correlated variables from the IVariableResolver
                    foreach (CorrelatedVariable variable in list)
                    {
                        variable.SetFromResolver(context.VariableResolver);
                    }
                    // Clear the cache in the context
                    context.QueryContext.ClearCache();
                }

                // Evaluate the plan,
                ITable t = plan.Evaluate(context.QueryContext);

                // The ANY operation
                Operator revPlainOp = op.Plain().Reverse();
                return(DataObject.Boolean(t.ColumnMatchesValue(0, revPlainOp, ob1)));
            }

            if (ob2.DataType is ArrayType)
            {
                Operator plainOp = op.Plain();
                var      expList = (IEnumerable <Expression>)ob2.Value;
                // Assume there are no matches
                DataObject retVal = DataObject.BooleanFalse;
                foreach (Expression exp in expList)
                {
                    DataObject expItem = exp.Evaluate(context.GroupResolver, context.VariableResolver, context.QueryContext);
                    // If null value, return null if there isn't otherwise a match found.
                    if (expItem.IsNull)
                    {
                        retVal = DataObject.BooleanNull;
                    }
                    else
                    {
                        var opExp = Expression.Operator(ob1, plainOp, expItem);
                        if (IsTrue(opExp.Evaluate()))
                        {
                            // If there is a match, the ANY set test is true
                            return(DataObject.BooleanTrue);
                        }
                    }
                }
                // No matches, so return either false or NULL.  If there are no matches
                // and no nulls, return false.  If there are no matches and there are
                // nulls present, return null.
                return(retVal);
            }

            throw new ApplicationException("Unknown RHS of ANY.");
        }