public virtual void CheckAccessRights(Session session) { if ((this.TargetTable != null) && !this.TargetTable.IsTemp()) { if (((this.TargetTable.GetOwner() != null) && this.TargetTable.GetOwner().IsSystem) && !session.GetUser().IsSystem) { throw Error.GetError(0x157d, this.TargetTable.GetName().Name); } if (!session.IsProcessingScript()) { this.TargetTable.CheckDataReadOnly(); } session.CheckReadWrite(); } if (!session.IsAdmin()) { for (int i = 0; i < this.Sequences.Length; i++) { session.GetGrantee().CheckAccess(this.Sequences[i]); } for (int j = 0; j < this.Routines.Length; j++) { if (!this.Routines[j].IsLibraryRoutine()) { session.GetGrantee().CheckAccess(this.Routines[j]); } } for (int k = 0; k < this.RangeVariables.Length; k++) { RangeVariable variable = this.RangeVariables[k]; if (variable.RangeTable.GetSchemaName() != SqlInvariants.SystemSchemaQname) { session.GetGrantee().CheckSelect(variable.RangeTable, variable.UsedColumns); } } int type = base.type; if (type <= 50) { switch (type) { case 0x13: session.GetGrantee().CheckDelete(this.TargetTable); return; case 50: session.GetGrantee().CheckInsert(this.TargetTable, this.InsertCheckColumns); return; } } else if (type == 0x52) { session.GetGrantee().CheckUpdate(this.TargetTable, this.UpdateCheckColumns); } else if ((type != 0x55) && (type == 0x80)) { session.GetGrantee().CheckInsert(this.TargetTable, this.InsertCheckColumns); session.GetGrantee().CheckUpdate(this.TargetTable, this.UpdateCheckColumns); } } }
/// <summary> /// Binds a LambdaToken to metadata. /// </summary> /// <param name="lambdaToken">Token to bind.</param> /// <param name="state">Object to hold the state of binding.</param> /// <returns>A metadata bound any or all node.</returns> internal LambdaNode BindLambdaToken(LambdaToken lambdaToken, BindingState state) { ExceptionUtils.CheckArgumentNotNull(lambdaToken, "LambdaToken"); ExceptionUtils.CheckArgumentNotNull(state, "state"); // Start by binding the parent token CollectionNode parent = this.BindParentToken(lambdaToken.Parent); RangeVariable rangeVariable = null; // Add the lambda variable to the stack if (lambdaToken.Parameter != null) { rangeVariable = NodeFactory.CreateParameterNode(lambdaToken.Parameter, parent); state.RangeVariables.Push(rangeVariable); } // Bind the expression SingleValueNode expression = this.BindExpressionToken(lambdaToken.Expression); // Create the node LambdaNode lambdaNode = NodeFactory.CreateLambdaNode(state, parent, expression, rangeVariable, lambdaToken.Kind); // Remove the lambda variable as it is now out of scope if (rangeVariable != null) { state.RangeVariables.Pop(); } return(lambdaNode); }
/// <summary> /// Creates an AnyNode or an AllNode from the given /// </summary> /// <param name="state">State of binding.</param> /// <param name="parent">Parent node to the lambda.</param> /// <param name="lambdaExpression">Bound Lambda expression.</param> /// <param name="newRangeVariable">The new range variable being added by this lambda node.</param> /// <param name="queryTokenKind">Token kind.</param> /// <returns>A new LambdaNode bound to metadata.</returns> internal static LambdaNode CreateLambdaNode( BindingState state, CollectionNode parent, SingleValueNode lambdaExpression, RangeVariable newRangeVariable, QueryTokenKind queryTokenKind) { LambdaNode lambdaNode; if (queryTokenKind == QueryTokenKind.Any) { lambdaNode = new AnyNode(new Collection <RangeVariable>(state.RangeVariables.ToList()), newRangeVariable) { Body = lambdaExpression, Source = parent, }; } else { Debug.Assert(queryTokenKind == QueryTokenKind.All, "LambdaQueryNodes must be Any or All only."); lambdaNode = new AllNode(new Collection <RangeVariable>(state.RangeVariables.ToList()), newRangeVariable) { Body = lambdaExpression, Source = parent, }; } return(lambdaNode); }
public bool Compare(RangeVariable rangeVariable1, RangeVariable rangeVariable2) { var range1 = (ResourceRangeVariable)rangeVariable1; var range2 = (ResourceRangeVariable)rangeVariable2; if (range1 == null || range2 == null) { return(range1 == range2); } if (range1.Kind != range2.Kind) { return(false); } if (range1.Name != range2.Name) { return(false); } if (range1.NavigationSource != range2.NavigationSource) { return(false); } if (!range1.StructuredTypeReference.IsEqual(range2.StructuredTypeReference)) { return(false); } if (!range1.TypeReference.IsEqual(range2.TypeReference)) { return(false); } return(Compare(range1.CollectionResourceNode, range2.CollectionResourceNode)); }
public static NonResourceRangeVariable ShouldBeNonentityRangeVariable(this RangeVariable variable, string expectedName) { Assert.NotNull(variable); var rangeVariable = Assert.IsType <NonResourceRangeVariable>(variable); Assert.Equal(expectedName, rangeVariable.Name); return(rangeVariable); }
/// <summary> /// Creates a <see cref="FilterClause"/>. /// </summary> /// <param name="expression">The expression - this should evaluate to a single value. Cannot be null.</param> /// <param name="rangeVariable">The parameter for the expression which represents a single value from the collection. Cannot be null.</param> /// <exception cref="System.ArgumentNullException">Throws if the input expression or rangeVariable is null.</exception> public ExpressionClause(SingleValueNode expression, RangeVariable rangeVariable) { ExceptionUtils.CheckArgumentNotNull(expression, "expression"); ExceptionUtils.CheckArgumentNotNull(rangeVariable, "parameter"); this.expression = expression; this.rangeVariable = rangeVariable; }
public static ResourceRangeVariable ShouldBeResourceRangeVariable(this RangeVariable variable, IEdmEntityTypeReference expectedTypeReference) { Assert.NotNull(variable); var node = Assert.IsType <ResourceRangeVariable>(variable); Assert.True(node.TypeReference.IsEquivalentTo(expectedTypeReference)); return(node); }
public void SetupChecks() { if (base.TargetTable != base.BaseTable) { QuerySpecification mainSelect = base.TargetTable.GetQueryExpression().GetMainSelect(); this.UpdatableTableCheck = mainSelect.CheckQueryCondition; this._checkRangeVariable = mainSelect.RangeVariables[0]; } }
private void SetAutoAttributesAsColumn(RangeVariable range, int i) { base.ColumnIndex = i; this.column = range.GetColumn(i); base.DataType = this.column.GetDataType(); this.ColumnName = range.GetColumnAlias(i); this.TableName = range.GetTableAlias(); this.rangeVariable = range; this.rangeVariable.AddColumn(base.ColumnIndex); }
public RangeVariable.RangeIteratorBase GetCheckIterator(RangeVariable rangeVariable) { IRangeIterator iterator = this.RangeIterators[1]; if (iterator == null) { iterator = rangeVariable.GetIterator(this.session); this.RangeIterators[1] = iterator; } return((RangeVariable.RangeIteratorBase)iterator); }
/// <summary> /// Binds a <see cref="RangeVariable"/> to create a LINQ <see cref="Expression"/> that /// represents the semantics of the <see cref="RangeVariable"/>. /// </summary> /// <param name="rangeVariable">The range variable to bind.</param> /// <returns>The LINQ <see cref="Expression"/> created.</returns> public virtual Expression BindRangeVariable(RangeVariable rangeVariable) { if (rangeVariable == null) { throw Error.ArgumentNull(nameof(rangeVariable)); } ParameterExpression parameter = _lambdaParameters[rangeVariable.Name]; return(ConvertNonStandardPrimitives(parameter)); }
/// <summary> /// Writes Range Variable node to string /// </summary> /// <param name="node">Node to write to string</param> /// <returns>String representation of node.</returns> private static string ToStringParameter(RangeVariable node) { if (node is EntityRangeVariable) { return(ToString((EntityRangeVariable)node)); } if (node is NonentityRangeVariable) { return(ToString((NonentityRangeVariable)node)); } return(String.Empty); }
/// <summary> /// Writes Range Variable node to string /// </summary> /// <param name="node">Node to write to string</param> /// <returns>String representation of node.</returns> private static string ToStringParameter(RangeVariable node) { if (node is ResourceRangeVariable) { return(ToString((ResourceRangeVariable)node)); } if (node is NonResourceRangeVariable) { return(ToString((NonResourceRangeVariable)node)); } return(String.Empty); }
/// <summary> /// Creates a RangeVariableReferenceNode for a given range variable /// </summary> /// <param name="rangeVariable">Name of the rangeVariable.</param> /// <returns>A new SingleValueNode (either an Entity or NonEntity RangeVariableReferenceNode.</returns> internal static SingleValueNode CreateRangeVariableReferenceNode(RangeVariable rangeVariable) { if (rangeVariable.Kind == RangeVariableKind.Nonentity) { return(new NonentityRangeVariableReferenceNode(rangeVariable.Name, (NonentityRangeVariable)rangeVariable)); } else { EntityRangeVariable entityRangeVariable = (EntityRangeVariable)rangeVariable; return(new EntityRangeVariableReferenceNode(entityRangeVariable.Name, entityRangeVariable)); } }
/// <summary> /// Redirects the comparison of parameter query nodes. /// </summary> /// <param name="left">Left side of comparison</param> /// <param name="right">Right side of comparison</param> /// <returns>True if equal, otherwise false</returns> private bool CompareParameters(RangeVariable left, RangeVariable right) { if (left is ResourceRangeVariable && right is ResourceRangeVariable) { return(this.Compare((ResourceRangeVariable)left, (ResourceRangeVariable)right)); } if (left is NonResourceRangeVariable && right is NonResourceRangeVariable) { return(this.Compare((NonResourceRangeVariable)left, (NonResourceRangeVariable)right)); } return(false); }
/// <summary> /// Redirects the comparison of parameter query nodes. /// </summary> /// <param name="left">Left side of comparison</param> /// <param name="right">Right side of comparison</param> /// <returns>True if equal, otherwise false</returns> private bool CompareParameters(RangeVariable left, RangeVariable right) { if (left is EntityRangeVariable && right is EntityRangeVariable) { return(this.Compare((EntityRangeVariable)left, (EntityRangeVariable)right)); } if (left is NonentityRangeVariable && right is NonentityRangeVariable) { return(this.Compare((NonentityRangeVariable)left, (NonentityRangeVariable)right)); } return(false); }
private LambdaExpression BindExpression(SingleValueNode expression, RangeVariable rangeVariable, Type elementType) { ParameterExpression filterParameter = Expression.Parameter(elementType, rangeVariable.Name); _lambdaParameters = new Dictionary <string, ParameterExpression>(); _lambdaParameters.Add(rangeVariable.Name, filterParameter); EnsureFlattenedPropertyContainer(filterParameter); Expression body = Bind(expression); return(Expression.Lambda(body, filterParameter)); }
/// <summary> /// Binds a parameter token. /// </summary> /// <param name="rangeVariableToken">The parameter token to bind.</param> /// <param name="state">The state of metadata binding.</param> /// <returns>The bound query node.</returns> internal static SingleValueNode BindRangeVariableToken(RangeVariableToken rangeVariableToken, BindingState state) { ExceptionUtils.CheckArgumentNotNull(rangeVariableToken, "rangeVariableToken"); RangeVariable rangeVariable = state.RangeVariables.SingleOrDefault(p => p.Name == rangeVariableToken.Name); if (rangeVariable == null) { throw new ODataException(ODataErrorStrings.MetadataBinder_ParameterNotInScope(rangeVariableToken.Name)); } return(NodeFactory.CreateRangeVariableReferenceNode(rangeVariable)); }
/// <summary> /// Bind a skip option /// </summary> /// <param name="syntax">a syntax tree containing the skip option</param> /// <param name="rangeVariable">the range variable that iterates over the top level collection</param> /// <param name="path">the top level path.</param> /// <returns>a nullable long representing this skip option</returns> public static long?BindSkip(SyntacticTree syntax, RangeVariable rangeVariable, ODataPath path) { if (syntax.Skip != null) { if (rangeVariable == null || !path.EdmType().IsEntityCollection()) { throw new ODataException(ODataErrorStrings.MetadataBinder_QueryOptionNotApplicable("$skip")); } return(MetadataBinder.ProcessSkip(syntax.Skip)); } return(null); }
/// <summary> /// Override this method to validate the parameter used in the filter query. /// </summary> /// <remarks> /// This method is intended to be called from method overrides in subclasses. This method also supports unit-testing scenarios and is not intended to be called from user code. /// Call the Validate method to validate a <see cref="FilterQueryOption"/> instance. /// </remarks> /// <param name="rangeVariable"></param> /// <param name="settings"></param> public virtual void ValidateRangeVariable(RangeVariable rangeVariable, ODataValidationSettings settings) { if (rangeVariable == null) { throw Error.ArgumentNull("rangeVariable"); } if (settings == null) { throw Error.ArgumentNull("settings"); } // no default validation logic here }
/// <summary> /// Determines the parent node. If the token has a parent, that token is bound. If not, then we /// use the implicit parameter from the BindingState as the parent node. /// </summary> /// <param name="segmentToken">Token to determine the parent node for.</param> /// <param name="state">Current state of binding.</param> /// <returns>A SingleValueQueryNode that is the parent node of the <paramref name="segmentToken"/>.</returns> private QueryNode DetermineParentNode(InnerPathToken segmentToken, BindingState state) { ExceptionUtils.CheckArgumentNotNull(segmentToken, "segmentToken"); ExceptionUtils.CheckArgumentNotNull(state, "state"); if (segmentToken.NextToken != null) { return(this.bindMethod(segmentToken.NextToken)); } else { RangeVariable implicitRangeVariable = state.ImplicitRangeVariable; return(NodeFactory.CreateRangeVariableReferenceNode(implicitRangeVariable)); } }
public override Expression ReplaceColumnReferences(RangeVariable range, Expression[] list) { if ((base.OpType == 2) && (this.rangeVariable == range)) { return(list[base.ColumnIndex]); } for (int i = 0; i < base.nodes.Length; i++) { if (base.nodes[i] != null) { base.nodes[i] = base.nodes[i].ReplaceColumnReferences(range, list); } } return(this); }
public override bool HasReference(RangeVariable range) { if (range == this.rangeVariable) { return(true); } for (int i = 0; i < base.nodes.Length; i++) { if ((base.nodes[i] != null) && base.nodes[i].HasReference(range)) { return(true); } } return(false); }
private void Recompile(Session session, Table newTable) { using (Scanner scanner = new Scanner(this.Check.GetSql())) { ParserDQL rdql1 = new ParserDQL(session, scanner); rdql1.compileContext.Reset(0); rdql1.Read(); rdql1.IsCheckOrTriggerCondition = true; Expression expression = rdql1.XreadBooleanValueExpression(); this.Check = expression; QuerySpecification specification = Expression.GetCheckSelect(session, newTable, this.Check); this.RangeVar = specification.RangeVariables[0]; this.RangeVar.SetForCheckConstraint(); } }
/// <summary> /// Bind an orderby option /// </summary> /// <param name="syntax">a syntac tree containing the orderby option</param> /// <param name="rangeVariable">the range variable that iterates over the top level collection</param> /// <param name="path">the top level path</param> /// <returns>an OrderByClause representing this orderby option</returns> public OrderByClause BindOrderBy(SyntacticTree syntax, RangeVariable rangeVariable, ODataPath path) { if (syntax.OrderByTokens != null && syntax.OrderByTokens.Any()) { if (rangeVariable == null || !path.EdmType().IsEntityCollection()) { throw new ODataException(ODataErrorStrings.MetadataBinder_QueryOptionNotApplicable("$orderby")); } OrderByBinder orderByBinder = new OrderByBinder(this.bindMethod); return(orderByBinder.BindOrderBy(this.bindingState, syntax.OrderByTokens)); } return(null); }
/// <summary> /// Bind a filter option /// </summary> /// <param name="syntax">a syntactic tree containing the filter option</param> /// <param name="rangeVariable">the range variable that iterates over the top level collection.</param> /// <returns>A filter clause representing this filter option</returns> public FilterClause BindFilter(SyntacticTree syntax, RangeVariable rangeVariable) { if (syntax.Filter != null) { if (rangeVariable == null) { throw new ODataException(ODataErrorStrings.MetadataBinder_QueryOptionNotApplicable("$filter")); } FilterBinder filterBinder = new FilterBinder(this.bindMethod, this.bindingState); return(filterBinder.BindFilter(syntax.Filter)); } return(null); }
public void RangeVariablesShouldBeSetCorrectly() { ResourceRangeVariable rangeVariable = (ResourceRangeVariable)NodeFactory.CreateImplicitRangeVariable(HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet()); Collection <RangeVariable> rangeVariables = new Collection <RangeVariable> { rangeVariable }; AllNode allNode = new AllNode(rangeVariables, rangeVariable); RangeVariable rangeVar = Assert.Single(allNode.RangeVariables); Assert.Equal(ExpressionConstants.It, rangeVar.Name); Assert.Equal(RangeVariableKind.Resource, rangeVar.Kind); ResourceRangeVariable returnedRangeVariable = Assert.IsType <ResourceRangeVariable>(rangeVar); Assert.Same(HardCodedTestModel.GetDogsSet(), returnedRangeVariable.NavigationSource); }
/// <summary> /// Binds a <see cref="RangeVariable"/> to create a LINQ <see cref="Expression"/> that /// represents the semantics of the <see cref="RangeVariable"/>. /// </summary> /// <param name="rangeVariable">The range variable to bind.</param> /// <returns>The LINQ <see cref="Expression"/> created.</returns> public virtual Expression BindRangeVariable(RangeVariable rangeVariable) { ParameterExpression parameter = null; // When we have a $this RangeVariable, we still create a $it parameter. // i.e $it => $it instead of $this => $this if (rangeVariable.Name == ODataThisParameterName) { parameter = _lambdaParameters[ODataItParameterName]; } else { parameter = _lambdaParameters[rangeVariable.Name]; } return(ConvertNonStandardPrimitives(parameter)); }
public void SetAttributesAsColumn(RangeVariable range, int i) { if (range.Variables != null) { base.ColumnIndex = i; this.column = range.GetColumn(i); base.DataType = this.column.GetDataType(); this.rangeVariable = range; } else { base.ColumnIndex = i; this.column = range.GetColumn(i); base.DataType = this.column.GetDataType(); this.rangeVariable = range; this.rangeVariable.AddColumn(base.ColumnIndex); } }
private void SetVariables() { if (this.Variables.Length == 0) { this.RangeVariables = (base.Parent == null) ? base.Root.GetParameterRangeVariables() : base.Parent.RangeVariables; } else { HashMappedList <string, ColumnSchema> variables = new HashMappedList <string, ColumnSchema>(); if ((base.Parent != null) && (base.Parent.ScopeVariables != null)) { for (int j = 0; j < base.Parent.ScopeVariables.Size(); j++) { variables.Add(base.Parent.ScopeVariables.GetKey(j), base.Parent.ScopeVariables.Get(j)); } } for (int i = 0; i < this.Variables.Length; i++) { string name = this.Variables[i].GetName().Name; if (!variables.Add(name, this.Variables[i])) { throw Error.GetError(0x15e6, name); } if (base.Root.GetParameterIndex(name) != -1) { throw Error.GetError(0x15e6, name); } } this.ScopeVariables = variables; RangeVariable variable = new RangeVariable(variables, true); if (!base.Root.IsTrigger()) { this.RangeVariables = new RangeVariable[] { base.Root.GetParameterRangeVariables()[0], variable }; } else { this.RangeVariables = new RangeVariable[base.Root.GetParameterRangeVariables().Length + 1]; Array.Copy(base.Root.GetParameterRangeVariables(), this.RangeVariables, (int)(this.RangeVariables.Length - 1)); this.RangeVariables[this.RangeVariables.Length - 1] = variable; } base.Root.VariableCount = variables.Size(); } }
public override void ValidateRangeVariable(RangeVariable rangeVariable, ODataValidationSettings settings) { IncrementCount("ValidateParameterQueryNode"); base.ValidateRangeVariable(rangeVariable, settings); }