DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlQueryExpression.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 using System.Collections.Generic;
19 using System.Linq;
20 
22 
23 namespace Deveel.Data.Sql.Expressions {
24  [Serializable]
25  public sealed class SqlQueryExpression : SqlExpression {
26  public SqlQueryExpression(IEnumerable<SelectColumn> selectColumns) {
27  SelectColumns = selectColumns;
28  FromClause = new FromClause();
29  }
30 
32  if (data.HasValue("Columns"))
33  SelectColumns = data.GetValue<SelectColumn[]>("Columns");
34 
35  Distinct = data.GetBoolean("Distinct");
36  FromClause = data.GetValue<FromClause>("From");
37  WhereExpression = data.GetValue<SqlExpression>("Where");
38  HavingExpression = data.GetValue<SqlExpression>("Having");
39  GroupBy = data.GetValue<SqlExpression[]>("GroupBy");
40  GroupMax = data.GetValue<ObjectName>("GroupMax");
41  NextComposite = data.GetValue<SqlQueryExpression>("NextComposite");
42 
43  if (data.HasValue("CompositeFunction"))
44  CompositeFunction = (CompositeFunction) data.GetInt32("CompositeFunction");
45 
46  IsCompositeAll = data.GetBoolean("CompositeAll");
47  }
48 
49  public IEnumerable<SelectColumn> SelectColumns { get; private set; }
50 
51  public FromClause FromClause { get; set; }
52 
53  public SqlExpression WhereExpression { get; set; }
54 
55  public SqlExpression HavingExpression { get; set; }
56 
57  public IEnumerable<SqlExpression> GroupBy { get; set; }
58 
59  public ObjectName GroupMax { get; set; }
60 
61  public SqlQueryExpression NextComposite { get; set; }
62 
63  public override SqlExpressionType ExpressionType {
64  get { return SqlExpressionType.Query; }
65  }
66 
67  public override bool CanEvaluate {
68  get { return true; }
69  }
70 
71  public CompositeFunction CompositeFunction { get; set; }
72 
73  public bool IsCompositeAll { get; set; }
74 
75  public bool Distinct { get; set; }
76 
77  protected override void GetData(SerializeData data) {
78  if (SelectColumns != null)
79  data.SetValue("Columns", SelectColumns.ToArray());
80 
81  data.SetValue("Distinct", Distinct);
82  data.SetValue("From", FromClause);
83  data.SetValue("Where", WhereExpression);
84  data.SetValue("Having", HavingExpression);
85 
86  if (GroupBy != null)
87  data.SetValue("GroupBy", GroupBy.ToArray());
88 
89  data.SetValue("GroupMax", GroupMax);
90  data.SetValue("NextComposite", NextComposite);
91  data.SetValue("CompositeFunction", (int)CompositeFunction);
92  data.SetValue("CompositeAll", IsCompositeAll);
93  }
94  }
95 }
void SetValue(string key, Type type, object value)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
SqlExpressionType
All the possible type of SqlExpression supported
A container for the FROM clause of a select statement.
Definition: FromClause.cs:32
Represents a column selected to be in the output of a select statement.
Definition: SelectColumn.cs:31
override void GetData(SerializeData data)
SqlQueryExpression(IEnumerable< SelectColumn > selectColumns)
CompositeFunction
The kind of composite function in a CompositeTable.
Defines the base class for instances that represent SQL expression tree nodes.