DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
VariableScopeExtensions.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 
20 using Deveel.Data.Types;
21 
22 namespace Deveel.Data.Sql.Variables {
23  public static class VariableScopeExtensions {
24  public static bool HasVariable(this IVariableScope scope, string variableName) {
25  return scope.VariableManager.VariableExists(variableName);
26  }
27 
28  public static Variable DefineVariable(this IVariableScope scope, VariableInfo variableInfo) {
29  return scope.VariableManager.DefineVariable(variableInfo);
30  }
31 
32  public static Variable DefineVariable(this IVariableScope scope, string variableName, SqlType variableType) {
33  return DefineVariable(scope, variableName, variableType, false);
34  }
35 
36  public static Variable DefineVariable(this IVariableScope scope, string variableName, SqlType variableType, bool constant) {
37  return scope.DefineVariable(new VariableInfo(variableName, variableType, constant));
38  }
39 
40  public static bool DropVariable(this IVariableScope scope, string variableName) {
41  return scope.VariableManager.DropVariable(variableName);
42  }
43 
44  public static Variable GetVariable(this IVariableScope scope, string variableName) {
45  return scope.VariableManager.GetVariable(variableName);
46  }
47 
48  public static Variable SetVariable(this IVariableScope scope, string variableName, DataObject value) {
49  var variable = scope.GetVariable(variableName);
50  if (variable == null)
51  variable = scope.DefineVariable(variableName, value.Type);
52 
53  variable.SetValue(value);
54  return variable;
55  }
56 
57  public static void SetBooleanVariable(this IVariableScope transaction, string name, bool value) {
58  transaction.SetVariable(name, DataObject.Boolean(value));
59  }
60 
61  public static void SetStringVariable(this IVariableScope transaction, string name, string value) {
62  transaction.SetVariable(name, DataObject.String(value));
63  }
64 
65  public static bool GetBooleanVariable(this IVariableScope transaction, string name) {
66  var variable = transaction.GetVariable(name);
67  if (variable == null)
68  return false;
69 
70  return variable.Value.AsBoolean();
71  }
72 
73  public static string GetStringVariable(this IVariableScope transaction, string name) {
74  var variable = transaction.GetVariable(name);
75  if (variable == null)
76  return null;
77 
78  return variable.Value;
79  }
80  }
81 }
SqlType Type
Gets the SqlType that defines the object properties
Definition: DataObject.cs:78
Variable DefineVariable(VariableInfo variableInfo)
static bool DropVariable(this IVariableScope scope, string variableName)
static Variable GetVariable(this IVariableScope scope, string variableName)
static DataObject String(string s)
Definition: DataObject.cs:592
static DataObject Boolean(SqlBoolean value)
Definition: DataObject.cs:544
static Variable DefineVariable(this IVariableScope scope, string variableName, SqlType variableType)
static bool HasVariable(this IVariableScope scope, string variableName)
static bool GetBooleanVariable(this IVariableScope transaction, string name)
bool VariableExists(string variableName)
static Variable DefineVariable(this IVariableScope scope, VariableInfo variableInfo)
static string GetStringVariable(this IVariableScope transaction, string name)
static void SetStringVariable(this IVariableScope transaction, string name, string value)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
static Variable DefineVariable(this IVariableScope scope, string variableName, SqlType variableType, bool constant)
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
static Variable SetVariable(this IVariableScope scope, string variableName, DataObject value)
bool DropVariable(string variableName)
Variable GetVariable(string variableName)
static void SetBooleanVariable(this IVariableScope transaction, string name, bool value)