DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
ReturnTypeVisitor.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 
19 using Deveel.Data;
20 using Deveel.Data.Routines;
21 using Deveel.Data.Types;
22 
23 namespace Deveel.Data.Sql.Expressions {
25  private readonly IRequest query;
27 
28  private SqlType sqlType;
29 
30  public ReturnTypeVisitor(IRequest query, IVariableResolver variableResolver) {
31  this.query = query;
32  this.variableResolver = variableResolver;
33 
34  sqlType = PrimitiveTypes.Null();
35  }
36 
37  public override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression) {
38  switch (binaryEpression.ExpressionType) {
44  sqlType = PrimitiveTypes.Numeric();
45  break;
46  default:
47  // we assume the expression type is already been check to be binary.
48  sqlType = PrimitiveTypes.Boolean();
49  break;
50 
51  }
52 
53  return base.VisitBinary(binaryEpression);
54  }
55 
57  sqlType = constant.Value.Type;
58 
59  return base.VisitConstant(constant);
60  }
61 
63  var invoke = new Invoke(expression.FunctioName, expression.Arguments);
64  var function = invoke.ResolveRoutine(query) as IFunction;
65  if (function != null)
66  sqlType = function.ReturnType(invoke, query, variableResolver);
67 
68  return base.VisitFunctionCall(expression);
69  }
70 
72  var name = reference.ReferenceName;
73  sqlType = variableResolver.ReturnType(name);
74 
75  return base.VisitReference(reference);
76  }
77 
78  public override SqlExpression Visit(SqlExpression expression) {
79  if (expression is QueryReferenceExpression)
80  return VisitQueryReference((QueryReferenceExpression) expression);
81 
82  return base.Visit(expression);
83  }
84 
86  sqlType = expression.QueryReference.ReturnType;
87  return expression;
88  }
89 
90  public SqlType GetType(SqlExpression expression) {
91  Visit(expression);
92  return sqlType;
93  }
94  }
95 }
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static SqlBinaryExpression Divide(SqlExpression left, SqlExpression right)
ObjectName ReferenceName
Gets the name of the object referenced by the expression.
SqlType Type
Gets the SqlType that defines the object properties
Definition: DataObject.cs:78
Defines a routine that is a function, that means it returns a value after its execution.
Definition: IFunction.cs:26
An expression that references an object within a context.
static SqlBinaryExpression Multiply(SqlExpression left, SqlExpression right)
static BooleanType Boolean()
SqlExpression VisitQueryReference(QueryReferenceExpression expression)
override SqlExpression VisitConstant(SqlConstantExpression constant)
override SqlExpression VisitReference(SqlReferenceExpression reference)
SqlExpressionType
All the possible type of SqlExpression supported
DataObject Value
Gets the constant value of the expression.
static NumericType Numeric()
ReturnTypeVisitor(IRequest query, IVariableResolver variableResolver)
static SqlBinaryExpression Modulo(SqlExpression left, SqlExpression right)
static SqlBinaryExpression Add(SqlExpression left, SqlExpression right)
override SqlExpression VisitBinary(SqlBinaryExpression binaryEpression)
static SqlBinaryExpression Subtract(SqlExpression left, SqlExpression right)
The information about the invocation of a routine, including the full name and arguments (as SqlExpre...
Definition: Invoke.cs:30
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
An interface to resolve a variable name to a constant object.
override SqlExpression VisitFunctionCall(SqlFunctionCallExpression expression)
Visits the expression that calls the function defined.
An expression that holds a constant value.
override SqlExpression Visit(SqlExpression expression)
Visits a given SQL expression.
Defines the base class for instances that represent SQL expression tree nodes.
SqlType GetType(SqlExpression expression)