DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SelectColumn.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 
21 namespace Deveel.Data.Sql.Expressions {
30  [Serializable]
31  public sealed class SelectColumn : IPreparable, ISerializable {
39  public SelectColumn(SqlExpression expression, string alias) {
40  if (expression == null)
41  throw new ArgumentNullException("expression");
42 
43  Expression = expression;
44  Alias = alias;
45  }
46 
53  public SelectColumn(SqlExpression expression)
54  : this(expression, null) {
55  }
56 
57  private SelectColumn(ObjectData data) {
58  Expression = data.GetValue<SqlExpression>("Expression");
59  Alias = data.GetString("Alias");
60  }
61 
65  public SqlExpression Expression { get; private set; }
66 
70  public string Alias { get; private set; }
71 
72  public bool IsGlob {
73  get {
74  return (Expression is SqlReferenceExpression) &&
75  ((SqlReferenceExpression) Expression).ReferenceName.IsGlob;
76  }
77  }
78 
79  public bool IsAll {
80  get {
81  return (Expression is SqlReferenceExpression) &&
82  ((SqlReferenceExpression) Expression).ReferenceName.IsGlob &&
83  ((SqlReferenceExpression)Expression).ReferenceName.FullName == "*";
84  }
85  }
86 
87  public ObjectName TableName {
88  get {
89  var refExp = Expression as SqlReferenceExpression;
90  if (refExp == null)
91  return null;
92 
93  return refExp.ReferenceName.Parent;
94  }
95  }
96 
97  public ObjectName ReferenceName {
98  get {
99  var refExp = Expression as SqlReferenceExpression;
100  if (refExp == null)
101  return null;
102 
103  return refExp.ReferenceName;
104  }
105  }
106 
110  internal ObjectName InternalName { get; set; }
111 
115  internal ObjectName ResolvedName { get; set; }
116 
118  data.SetValue("Expression", Expression);
119  data.SetValue("Alias", Alias);
120  }
121 
124  var exp = Expression;
125  if (exp != null) {
126  exp = exp.Prepare(preparer);
127  }
128 
129  return new SelectColumn(exp, Alias);
130  }
131 
142  public static SelectColumn Glob(string glob) {
144  }
145  }
146 }
ObjectName ReferenceName
Gets the name of the object referenced by the expression.
void GetData(SerializeData data)
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
An expression that references an object within a context.
SelectColumn(SqlExpression expression)
Constructs a new SelectColumn for the given expression.
Definition: SelectColumn.cs:53
void SetValue(string key, Type type, object value)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
An interface used to prepare a SqlExpression object.
Represents a column selected to be in the output of a select statement.
Definition: SelectColumn.cs:31
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
object Prepare(IExpressionPreparer preparer)
Converts the underlying value of this instance into an object that can be evaluated by an expression...
static SqlReferenceExpression Reference(ObjectName objectName)
Defines the base class for instances that represent SQL expression tree nodes.
static SelectColumn Glob(string glob)
Creates a special SelectColumn that is used to select all the columns in a table. ...
A contract for objects that participate to a SqlExpression.Prepare phase of an expression evaluation...
Definition: IPreparable.cs:30
SelectColumn(SqlExpression expression, string alias)
Constructs a new SelectColumn for the given expression and aliased with the given name...
Definition: SelectColumn.cs:39