public View(ViewInfo viewInfo) { if (viewInfo == null) throw new ArgumentNullException("viewInfo"); ViewInfo = viewInfo; }
public static void DefineView(this IQuery 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 IQuery 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.Direct()) { systemContext.GrantToUserOnTable(viewInfo.ViewName, context.UserName(), Privileges.TableAll); } }
public void DefineView(ViewInfo viewInfo) { if (viewInfo == null) throw new ArgumentNullException("viewInfo"); var dataTableInfo = viewInfo.TableInfo; var viewTable = Transaction.GetMutableTable(ViewTableName); var viewName = dataTableInfo.TableName; var query = viewInfo.QueryExpression; var viewInfoData = viewInfo.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, Field.Binary(viewInfoData)); // 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.OnObjectCreated(DbObjectType.View, viewName); // Change to the view table viewTableChanged = true; }
public static void Serialize(ViewInfo viewInfo, BinaryWriter writer) { var serializer = new BinarySerializer(); serializer.Serialize(writer, viewInfo); }
protected override void ExecuteStatement(ExecutionContext context) { // We have to execute the plan to get the TableInfo that represents the // result of the view execution. var table = QueryPlan.Evaluate(context.Request); var tableInfo = table.TableInfo.Alias(ViewName); var viewInfo = new ViewInfo(tableInfo, QueryExpression, QueryPlan); context.Request.Query.DefineView(viewInfo, ReplaceIfExists); }
private void DefineView(ExecutionContext context, ViewInfo viewInfo, bool replaceIfExists) { //var tablesInPlan = viewInfo.QueryPlan.DiscoverAccessedResources(); //foreach (var tableName in tablesInPlan) { // if (!context.User.CanSelectFromTable(tableName)) // throw new InvalidAccessException(context.User.Name, tableName); //} if (context.Request.Access().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.Request.Access().DropObject(DbObjectType.View, viewInfo.ViewName); } context.Request.Access().CreateView(viewInfo); // The initial grants for a view is to give the user who created it // full access. // TODO: Verify if we need a system session to assign this... context.Request.Access().GrantOn(DbObjectType.View, viewInfo.ViewName, context.User.Name, PrivilegeSets.TableAll); }