2 using System.Collections.Generic;
9 namespace Deveel.Data.Sql.Views {
12 return context.ObjectExists(
DbObjectType.View, viewName);
16 var tablesInPlan = viewInfo.
QueryPlan.DiscoverTableNames();
17 foreach (var tableName
in tablesInPlan) {
18 if (!context.UserCanSelectFromTable(tableName))
22 if (context.ViewExists(viewInfo.ViewName)) {
24 throw new InvalidOperationException(
25 String.Format(
"The view {0} already exists and the REPLCE clause was not specified.", viewInfo.ViewName));
27 context.DropObject(
DbObjectType.View, viewInfo.ViewName);
30 context.CreateObject(viewInfo);
34 using (var systemContext = context.ForSystemUser()) {
35 systemContext.GrantToUserOnTable(viewInfo.ViewName, context.UserName(),
Privileges.TableAll);
42 var table = queryPlan.
Evaluate(context);
43 var tableInfo = table.TableInfo.Alias(viewName);
45 var viewInfo =
new ViewInfo(tableInfo, null, queryPlan);
46 context.DefineView(viewInfo, replaceIfExists);
50 DropView(context, viewName,
false);
54 context.DropViews(
new[] { viewName }, ifExists);
58 DropViews(context, viewNames,
false);
62 var viewNameList = viewNames.ToList();
63 foreach (var tableName
in viewNameList) {
64 if (!context.UserCanDropObject(
DbObjectType.View, tableName))
72 foreach (var viewName
in viewNameList) {
74 if (!context.ViewExists(viewName)) {
75 throw new ObjectNotFoundException(viewName, String.Format(
"The view '{0}' does not exist and cannot be dropped.", viewName));
80 foreach (var viewName
in viewNameList) {
82 if (context.ViewExists(viewName)) {
87 context.RevokeAllGrantsOnView(viewName);
97 var view = context.GetView(viewName);
98 return view == null ? null : view.QueryPlan;
ITable Evaluate(IRequest context)
static bool ViewExists(this IQueryContext context, ObjectName viewName)
static void DropViews(this IQueryContext context, IEnumerable< ObjectName > viewNames)
Provides a context for executing queries, accessing the system resources and evaluation context...
Describes the name of an object within a database.
static void DropView(this IQueryContext context, ObjectName viewName, bool ifExists)
static void DropView(this IQueryContext context, ObjectName viewName)
static void DropViews(this IQueryContext context, IEnumerable< ObjectName > viewNames, bool onlyIfExists)
static View GetView(this IQueryContext context, ObjectName viewName)
A node element of a query plan tree. /summary>
static void DefineView(this IQueryContext context, ViewInfo viewInfo, bool replaceIfExists)
static IQueryPlanNode GetViewQueryPlan(this IQueryContext context, ObjectName viewName)
static void DefineView(this IQueryContext context, ObjectName viewName, IQueryPlanNode queryPlan, bool replaceIfExists)
DbObjectType
The kind of objects that can be handled by a database system and its managers