DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
DropViewStatement.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.IO;
20 using System.Linq;
21 
23 using Deveel.Data.Sql.Tables;
24 using Deveel.Data.Sql.Views;
25 
26 namespace Deveel.Data.Sql.Statements {
28  public DropViewStatement(string[] viewNames)
29  : this(viewNames, false) {
30  }
31 
32  public DropViewStatement(string[] viewNames, bool ifExists) {
33  ViewNames = viewNames;
34  IfExists = ifExists;
35  }
36 
37  public string[] ViewNames { get; private set; }
38 
39  public bool IfExists { get; set; }
40 
42  var viewNameList = ViewNames.ToList();
43  var dropViews = new List<string>();
44 
45  foreach (var tableName in viewNameList) {
46  if (dropViews.Contains(tableName, StringComparer.OrdinalIgnoreCase))
47  throw new StatementPrepareException(String.Format("Duplicated table name '{0}' in the list of tables to drop.",
48  tableName));
49 
50  dropViews.Add(tableName);
51  }
52 
53  var resolvedNames = dropViews.Select(context.Query.ResolveObjectName);
54 
55  return new Prepared(resolvedNames.ToArray(), IfExists);
56  }
57 
58  #region Prepared
59 
60  [Serializable]
62  public ObjectName[] ViewNames { get; set; }
63 
64  public bool IfExists { get; set; }
65 
66  public Prepared(ObjectName[] viewNames, bool ifExists) {
67  ViewNames = viewNames;
68  IfExists = ifExists;
69  }
70 
71  private Prepared(ObjectData data) {
72  ViewNames = data.GetValue<ObjectName[]>("ViewNames");
73  IfExists = data.GetBoolean("IfExists");
74  }
75 
76  protected override void GetData(SerializeData data) {
77  data.SetValue("ViewNames", ViewNames);
78  data.SetValue("IfExists", IfExists);
79  }
80 
81  protected override void ExecuteStatement(ExecutionContext context) {
82  context.Request.Query.DropViews(ViewNames, IfExists);
83  }
84  }
85 
86  #endregion
87  }
88 }
An exception that happens during the SqlStatement.Prepare(IExpressionPreparer, IQueryContext).
void SetValue(string key, Type type, object value)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
DropViewStatement(string[] viewNames, bool ifExists)
Prepared(ObjectName[] viewNames, bool ifExists)
Represents the foundation class of SQL statements to be executed.
Definition: SqlStatement.cs:32
override void ExecuteStatement(ExecutionContext context)