18 using System.Collections.Generic;
25 namespace Deveel.Data.Sql.Views {
28 return context.ObjectExists(
DbObjectType.View, viewName);
32 var tablesInPlan = viewInfo.
QueryPlan.DiscoverTableNames();
33 foreach (var tableName
in tablesInPlan) {
34 if (!context.UserCanSelectFromTable(tableName))
38 if (context.ViewExists(viewInfo.ViewName)) {
40 throw new InvalidOperationException(
41 String.Format(
"The view {0} already exists and the REPLCE clause was not specified.", viewInfo.ViewName));
43 context.DropObject(
DbObjectType.View, viewInfo.ViewName);
46 context.CreateObject(viewInfo);
50 using (var systemContext = context.Direct()) {
51 systemContext.GrantToUserOnTable(viewInfo.ViewName, context.UserName(),
Privileges.TableAll);
58 var table = queryPlan.
Evaluate(context);
59 var tableInfo = table.TableInfo.Alias(viewName);
61 var viewInfo =
new ViewInfo(tableInfo, null, queryPlan);
62 context.DefineView(viewInfo, replaceIfExists);
66 DropView(context, viewName,
false);
70 context.DropViews(
new[] { viewName }, ifExists);
73 public static void DropViews(
this IQuery context, IEnumerable<ObjectName> viewNames) {
74 DropViews(context, viewNames,
false);
77 public static void DropViews(
this IQuery context, IEnumerable<ObjectName> viewNames,
bool onlyIfExists) {
78 var viewNameList = viewNames.ToList();
79 foreach (var tableName
in viewNameList) {
80 if (!context.UserCanDropObject(
DbObjectType.View, tableName))
88 foreach (var viewName
in viewNameList) {
90 if (!context.ViewExists(viewName)) {
91 throw new ObjectNotFoundException(viewName, String.Format(
"The view '{0}' does not exist and cannot be dropped.", viewName));
96 foreach (var viewName
in viewNameList) {
98 if (context.ViewExists(viewName)) {
103 context.RevokeAllGrantsOnView(viewName);
113 var view = context.GetView(viewName);
114 return view == null ? null : view.QueryPlan;
ITable Evaluate(IRequest context)
Describes the name of an object within a database.
static void DropView(this IQuery context, ObjectName viewName, bool ifExists)
static void DefineView(this IQuery context, ViewInfo viewInfo, bool replaceIfExists)
A node element of a query plan tree. /summary>
static void DropViews(this IQuery context, IEnumerable< ObjectName > viewNames)
static void DropView(this IQuery context, ObjectName viewName)
static void DefineView(this IQuery context, ObjectName viewName, IQueryPlanNode queryPlan, bool replaceIfExists)
static View GetView(this IQuery context, ObjectName viewName)
static IQueryPlanNode GetViewQueryPlan(this IQuery context, ObjectName viewName)
static void DropViews(this IQuery context, IEnumerable< ObjectName > viewNames, bool onlyIfExists)
static bool ViewExists(this IQuery context, ObjectName viewName)
DbObjectType
The kind of objects that can be handled by a database system and its managers