18 using System.Collections.Generic;
28 namespace Deveel.Data.Sql.Expressions {
33 this.context = context;
38 return VisitQueryReference((QueryReferenceExpression) expression);
40 return base.Visit(expression);
45 var value = reference.
Evaluate(context.VariableResolver);
50 var info =
new List<BinaryEvaluateInfo> {
53 }.OrderByDescending(x => x.Precedence);
55 foreach (var evaluateInfo
in info) {
56 evaluateInfo.Expression = Visit(evaluateInfo.Expression);
59 return info.OrderBy(x => x.Offset)
60 .Select(x => x.Expression)
73 var result = EvaluateBinary(value1, binaryType, value2);
79 if (binaryType.IsAll())
80 return left.
Any(binaryType.SubQueryPlainType(), right, context);
81 if (binaryType.IsAny())
82 return left.
All(binaryType.SubQueryPlainType(), right, context);
86 return left.
Add(right);
108 return left.
Is(right);
110 return left.
IsNot(right);
112 return left.
IsLike(right);
116 return left.
And(right);
118 return left.
Or(right);
120 return left.
XOr(right);
128 var sides = EvaluateSides(binaryEpression);
130 var newLeft = sides[0];
131 var newRight = sides[1];
133 return EvaluateBinary(newLeft, binaryEpression.
ExpressionType, newRight);
137 var valueExp = Visit(castExpression.
Value);
142 var casted = value.CastTo(castExpression.
SqlType);
181 if (context != null) {
182 request = context.Request;
183 variableResolver = context.VariableResolver;
184 groupResolver = context.GroupResolver;
188 var result = invoke.Execute(request, variableResolver, groupResolver);
189 if (!result.HasReturnValue)
195 }
catch (Exception ex) {
201 if (context.Request == null)
205 var planner = context.Request.Context.QueryPlanner();
206 var plan = planner.PlanQuery(
new QueryInfo(context.Request, query));
210 }
catch (Exception ex) {
218 if (context.VariableResolver == null)
222 var value = context.VariableResolver.Resolve(refName);
226 }
catch (Exception ex) {
232 var operand = Visit(unary.
Operand);
243 return operand.
Plus();
253 if (context.Request == null)
267 variableName = ((SqlVariableReferenceExpression) reference).VariableName;
269 var refName = ((SqlReferenceExpression) reference).ReferenceName;
270 if (refName.Parent != null)
271 throw new NotSupportedException(
string.Format(
"Reference to '{0}' is not supported.", refName));
273 variableName = refName.Name;
275 throw new NotSupportedException();
279 context.Request.SetVariable(variableName, valueExpression);
280 }
catch (Exception ex) {
291 list = VisitExpressionList(list);
298 if (list.Length == 1 &&
309 if (context.Request == null)
311 if (context.VariableResolver == null)
315 var variable = context.Request.FindVariable(refName);
316 if (variable == null)
340 #region BinaryEvaluateInfo
344 public int Offset {
get; set; }
346 public int Precedence {
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
override SqlExpressionType ExpressionType
ExpressionEvaluatorVisitor(EvaluateContext context)
override SqlExpression Visit(SqlExpression expression)
Visits a given SQL expression.
ObjectName ReferenceName
Gets the name of the object referenced by the expression.
DataObject Multiply(DataObject other)
SqlExpression Operand
Gets the operand expression that is computed.
override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression)
SqlExpression ValueExpression
SqlExpression Value
Gets the expression whose evaluated value will be converted.
An error occurring while evaluating an SqlExpression.
static readonly SqlArray Null
A SQL array that is equivalent to null.
An expression that references an object within a context.
A long string in the system.
Handles expressions computed against an unary operator.
SqlExpression EvaluateBinary(SqlExpression left, SqlExpressionType binaryType, SqlExpression right)
SqlType SqlType
Gets the destination type of the conversion
override SqlExpression VisitTuple(SqlTupleExpression expression)
DataObject Divide(DataObject other)
static DataObject Null(SqlType type)
An SqlExpression that will cast a value retrieved by the evaluation of another expression into a give...
DataObject IsLike(DataObject pattern)
When the type of this object is a string, this method verifies if the input pattern is compatible (
DataObject Modulus(DataObject other)
override SqlExpression VisitVariableReference(SqlVariableReferenceExpression reference)
override SqlExpression VisitFunctionCall(SqlFunctionCallExpression expression)
Visits the expression that calls the function defined.
DataObject IsSmallerThan(DataObject other)
SqlExpressionType
All the possible type of SqlExpression supported
SqlExpression TestExpression
SqlExpression FalseExpression
override SqlExpression VisitAssign(SqlAssignExpression assign)
DataObject IsEqualTo(DataObject other)
Compares to the given object to verify if is it equal to the current.
DataObject EvaluateUnary(DataObject operand, SqlExpressionType unaryType)
DataObject IsNotLike(DataObject pattern)
DataObject IsSmallerOrEqualThan(DataObject other)
Defines a contract used by grouping functions to find information about the current group being evalu...
SqlExpression[] Arguments
override SqlExpression VisitReference(SqlReferenceExpression reference)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
DataObject IsGreaterThan(DataObject other)
override SqlExpression VisitConditional(SqlConditionalExpression conditional)
The information about the invocation of a routine, including the full name and arguments (as SqlExpre...
DataObject Is(DataObject other)
Compares to the given object to verify if is it compatible.
DataObject XOr(DataObject other)
DataObject IsGreterOrEqualThan(DataObject other)
DataObject EvaluateBinary(DataObject left, SqlExpressionType binaryType, DataObject right)
An interface to resolve a variable name to a constant object.
override SqlExpression VisitUnary(SqlUnaryExpression unary)
An expression that holds a constant value.
DataObject IsNotEqualTo(DataObject other)
Compares to the given object to verify if is it not equal to the current.
override SqlExpression VisitQuery(SqlQueryExpression query)
SqlExpression TrueExpression
DataObject Negate()
Negates the current underlying value of the object.
override SqlExpression VisitCast(SqlCastExpression castExpression)
override SqlExpressionType ExpressionType
SqlExpression[] EvaluateSides(SqlBinaryExpression binary)
DataObject And(DataObject other)
SqlExpression[] Expressions
QueryReference QueryReference
Defines the base class for instances that represent SQL expression tree nodes.
DataObject Any(SqlExpressionType type, DataObject other, EvaluateContext context)
static SqlConstantExpression Constant(object value)
An object that provides methods for accessing a finite collection of SQL expressions.
readonly EvaluateContext context
abstract SqlExpressionType ExpressionType
Gets the type code of this SQL expression.
Encapsulates the elements needed to evaluate an SqlExpression
DataObject IsNot(DataObject other)
Compares the given object to verify if it is not compatible with this one.
DataObject All(SqlExpressionType type, DataObject other, EvaluateContext context)
DataObject Subtract(DataObject other)
DataObject Add(DataObject other)
Adds the given value to this object value.
A visitor for SqlExpression objects.
DataObject Evaluate(IVariableResolver resolver)
DataObject Or(DataObject other)
SqlExpression ReferenceExpression
SqlExpression VisitQueryReference(QueryReferenceExpression expression)