DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
InsertSelectStatement.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 
23 using Deveel.Data.Sql.Query;
24 using Deveel.Data.Sql.Tables;
25 
26 namespace Deveel.Data.Sql.Statements {
28  public InsertSelectStatement(string tableName, IEnumerable<string> columnNames, SqlQueryExpression queryExpression) {
29  TableName = tableName;
30  ColumnNames = columnNames;
31  QueryExpression = queryExpression;
32  }
33 
34  public string TableName { get; private set; }
35 
36  public IEnumerable<string> ColumnNames { get; private set; }
37 
38  public SqlQueryExpression QueryExpression { get; private set; }
39 
41  var tableName = request.Query.ResolveTableName(TableName);
42  if (tableName == null)
43  throw new ObjectNotFoundException(ObjectName.Parse(TableName));
44 
45  var columns = new string[0];
46  if (ColumnNames != null)
47  columns = ColumnNames.ToArray();
48 
49  // TODO: Verify the columns!!!
50 
51  var queryPlan = request.Context.QueryPlanner().PlanQuery(new QueryInfo(request, QueryExpression));
52  return new Prepared(tableName, columns, queryPlan);
53  }
54 
55  #region PreparedInsertStatement
56 
57  [Serializable]
59  internal Prepared(ObjectName tableName, string[] columnNames, IQueryPlanNode queryPlan) {
60  TableName = tableName;
61  ColumnNames = columnNames;
62  QueryPlan = queryPlan;
63  }
64 
65  private Prepared(ObjectData data) {
66  TableName = data.GetValue<ObjectName>("TableName");
67  QueryPlan = data.GetValue<IQueryPlanNode>("QueryPlan");
68  ColumnNames = data.GetValue<string[]>("ColumnNames");
69  }
70 
71  public ObjectName TableName { get; private set; }
72 
73  public IQueryPlanNode QueryPlan { get; private set; }
74 
75  public string[] ColumnNames { get; private set; }
76 
77  protected override void GetData(SerializeData data) {
78  data.SetValue("TableName", TableName);
79  data.SetValue("QueryPlan", QueryPlan);
80  data.SetValue("ColumnNames", ColumnNames);
81  }
82 
83  protected override void ExecuteStatement(ExecutionContext context) {
84  throw new NotImplementedException();
85  }
86  }
87 
88  #endregion
89  }
90 }
Prepared(ObjectName tableName, string[] columnNames, IQueryPlanNode queryPlan)
static ObjectName Parse(string s)
Parses the given string into a ObjectName object.
Definition: ObjectName.cs:139
void SetValue(string key, Type type, object value)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
InsertSelectStatement(string tableName, IEnumerable< string > columnNames, SqlQueryExpression queryExpression)
A node element of a query plan tree. /summary>
Represents the foundation class of SQL statements to be executed.
Definition: SqlStatement.cs:32
override void ExecuteStatement(ExecutionContext context)