Exemple #1
0
        public View(ViewInfo viewInfo)
        {
            if (viewInfo == null)
                throw new ArgumentNullException("viewInfo");

            ViewInfo = viewInfo;
        }
Exemple #2
0
        public void DefineView(ViewInfo viewInfo)
        {
            if (viewInfo == null)
                throw new ArgumentNullException("viewInfo");

            var dataTableInfo = viewInfo.TableInfo;
            var viewTable = Transaction.GetMutableTable(SystemSchema.ViewTableName);

            var viewName = dataTableInfo.TableName;
            var query = viewInfo.QueryExpression;
            var planData = viewInfo.QueryPlan.AsBinary();

            // Create the view record
            var rdat = viewTable.NewRow();
            rdat.SetValue(0, dataTableInfo.SchemaName.Name);
            rdat.SetValue(1, dataTableInfo.Name);
            rdat.SetValue(2, query.ToString());
            rdat.SetValue(3, DataObject.Binary(planData));

            // Find the entry from the view that equals this name
            var t = FindViewEntry(viewName);

            // Delete the entry if it already exists.
            if (t.RowCount == 1) {
                viewTable.Delete(t);
            }

            // Insert the new view entry in the system view table
            viewTable.AddRow(rdat);

            // Notify that this database object has been successfully created.
            Transaction.Registry.RegisterEvent(new ObjectCreatedEvent(viewName, DbObjectType.View));

            // Change to the view table
            viewTableChanged = true;
        }
        public static void DefineView(this IQueryContext context, ViewInfo viewInfo)
        {
            var tablesInPlan = viewInfo.QueryPlan.DiscoverTableNames();
            foreach (var tableName in tablesInPlan) {
                if (!context.UserCanSelectFromTable(tableName))
                    throw new InvalidOperationException(String.Format("User '{0}' cannot access the table '{1}' in the view query plan.", context.User(), tableName));
            }

            context.CreateObject(viewInfo);
        }
Exemple #4
0
        public static void Serialize(ViewInfo viewInfo, BinaryWriter writer)
        {
            TableInfo.Serialize(viewInfo.TableInfo, writer);
            SqlExpression.Serialize(viewInfo.QueryExpression, writer);

            var queryPlanType = viewInfo.QueryPlan.GetType();
            writer.Write(queryPlanType.FullName);
            QueryPlanSerializers.Serialize(viewInfo.QueryPlan, writer);
        }
        public static void DefineView(this IQueryContext context, ObjectName viewName, IQueryPlanNode queryPlan, bool replaceIfExists)
        {
            // We have to execute the plan to get the TableInfo that represents the
            // result of the view execution.
            var table = queryPlan.Evaluate(context);
            var tableInfo = table.TableInfo.Alias(viewName);

            var viewInfo = new ViewInfo(tableInfo, null, queryPlan);
            context.DefineView(viewInfo, replaceIfExists);
        }
        public static void DefineView(this IQueryContext context, ViewInfo viewInfo, bool replaceIfExists)
        {
            var tablesInPlan = viewInfo.QueryPlan.DiscoverTableNames();
            foreach (var tableName in tablesInPlan) {
                if (!context.UserCanSelectFromTable(tableName))
                    throw new InvalidAccessException(context.UserName(), tableName);
            }

            if (context.ViewExists(viewInfo.ViewName)) {
                if (!replaceIfExists)
                    throw new InvalidOperationException(
                        String.Format("The view {0} already exists and the REPLCE clause was not specified.", viewInfo.ViewName));

                context.DropObject(DbObjectType.View, viewInfo.ViewName);
            }

            context.CreateObject(viewInfo);

            // The initial grants for a view is to give the user who created it
            // full access.
            using (var systemContext = context.ForSystemUser()) {
                systemContext.GrantToUserOnTable(viewInfo.ViewName, Privileges.TableAll);
            }
        }