23 namespace Deveel.Data.Sql.Variables {
26 var currentContext = context;
27 while (currentContext != null) {
29 var scope = (IVariableScope) currentContext;
30 var variable = scope.GetVariable(variableName);
35 currentContext = currentContext.
Parent;
44 var currentContext = context;
45 while (currentContext != null) {
47 var scope = (IVariableScope)currentContext;
48 if (scope.HasVariable(variableName))
52 currentContext = currentContext.
Parent;
61 var currentContext = context;
62 while (currentContext != null) {
64 var scope = (IVariableScope)currentContext;
65 if (scope.HasVariable(variableName))
66 return scope.DropVariable(variableName);
69 currentContext = currentContext.
Parent;
79 throw new InvalidOperationException(
String.Format(
"Variable '{0}' already defined in the context hierarchy.", variableInfo.
VariableName));
81 var currentContext = context;
82 while (currentContext != null) {
84 var scope = (IVariableScope)currentContext;
85 return scope.DefineVariable(variableInfo);
88 currentContext = currentContext.
Parent;
96 return DeclareVariable(context, variableName, variableType,
false);
100 return context.DeclareVariable(
new VariableInfo(variableName, variableType, constant));
104 var currentContext = context;
105 while (currentContext != null) {
107 var scope = (IVariableScope) currentContext;
108 if (scope.HasVariable(variableName)) {
110 var constantValue = value.EvaluateToConstant(null, context.VariableResolver());
111 return scope.SetVariable(variableName, constantValue);
115 currentContext = currentContext.Parent;
118 currentContext = context;
119 while (currentContext != null) {
121 var scope = (IVariableScope)currentContext;
123 var constantValue = value.EvaluateToConstant(null, context.VariableResolver());
124 return scope.SetVariable(variableName, constantValue);
127 currentContext = currentContext.Parent;
138 #region ContextVariableResolver
144 this.context = context;
148 var variable = context.FindVariable(variableName.
Name);
149 if (variable == null)
152 return variable.Value;
156 var variable = context.FindVariable(variableName.
Name);
157 if (variable == null)
160 return variable.Type;
static bool VariableExists(this IContext context, string variableName)
A long string in the system.
static IVariableResolver VariableResolver(this IContext context)
Describes the name of an object within a database.
static Variable DeclareVariable(this IContext context, string variableName, SqlType variableType, bool constant)
static bool DropVariable(this IContext context, string variableName)
static Variable FindVariable(this IContext context, string variableName)
static Variable SetVariable(this IContext context, string variableName, SqlExpression value)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Defines the properties of a specific SQL Type and handles the values compatible.
static Variable DeclareVariable(this IContext context, VariableInfo variableInfo)
An interface to resolve a variable name to a constant object.
ContextVariableResolver(IContext context)
string Name
Gets the name of the object being referenced.
SqlType ReturnType(ObjectName variableName)
Returns the SqlType of object the given variable is.
Defines the base class for instances that represent SQL expression tree nodes.
static Variable DeclareVariable(this IContext context, string variableName, SqlType variableType)
DataObject Resolve(ObjectName variableName)
Returns the value of a given variable.