Пример #1
0
        public static void Refresh(DBView v)
        {
            //reset
            DBObjectManager.BeforeRefresh(v);

            //self

            //columns
            DBObjectManager.RefreshColumns(v);

            //properties
            DBObjectManager.RefreshProperties(v);

            //intact
            DBObjectManager.AfterRefresh(v);
        }
Пример #2
0
        public static void Refresh(DBTable t)
        {
            //reset state and collections
            DBObjectManager.BeforeRefresh(t);

            //columns
            DBObjectManager.RefreshColumns(t);

            //primary key
            RefreshPrimaryKey(t);

            //triggers
            RefreshTriggers(t);

            //policies (select, update, delete)
            RefreshPolicies(t);

            //extensions (views/computed/secure) for extra columns
            RefreshExtensions(t);

            //table level properties
            RefreshTableProperties(t);

            //business
            RefreshBusinessProcedures(t);

            //foreign key relations
            RefreshForeignKeys(t);

            //check constraints
            RefreshCheckConstraints(t);

            //default constraints
            RefreshDefaultConstraints(t);

            //properties
            DBObjectManager.RefreshProperties(t);
            
            //state intact
            DBObjectManager.AfterRefresh(t);
        }
Пример #3
0
        public static void RefreshExtensions(DBTable t)
        {
            var sql = string.Format(@"
                select
		            SchemaName = s.name,
		            ViewName = v.name,
		            Definition = m.definition
	            from
		            sys.schemas s
		            join sys.views v on v.schema_id = s.schema_id
		            join sys.sql_modules m on m.object_id = v.object_id
	            where
		            s.name in ('computed', 'views', 'secure')
                    and v.name = '{0}_{1}'", t.Schema.Name, t.Name);
			
        	var cmd = new DBCommand{ Sql = sql, Owner = t, Description = "Get Table Extensions" };
            
        	t.Extensions.Clear();
        	t.Extensions.AddRange(DBProjectManager.ExecuteQuery(cmd).AsEnumerable().Select(x => new DBView()
            {
                OnAlreadyExists = DBObject.DBOnExists.PerformActionWithNoExistenceCheck,
                Name = x["ViewName"].ToString(),
				Schema = t.Schema.Database.Schemas.FirstOrDefault(s => s.Name == x["SchemaName"].ToString()),
                DefinitionSQL = x["Definition"].ToString(),
                Action = DB.DBAction.Alter,
                Connection = t.Connection,
                State = EngineManager.DBObject.DBObjectState.Intact
        	}).ToList());

            //objects for views
			t.ExtendedView = t.Extensions.FirstOrDefault(x => x.Schema.Name == "views");
			t.ComputedView = t.Extensions.FirstOrDefault(x => x.Schema.Name == "computed");
			t.SecureView = t.Extensions.FirstOrDefault(x => x.Schema.Name == "secure");

            foreach (var e in t.Extensions)
                DBObjectManager.RefreshColumns(e);
        }
        private List <DBColumn> m_list = new List <DBColumn>(); //stores the list
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            if (context.Instance is DBTable)
            {
                var table = context.Instance as DBTable;
                m_list = table.Columns.ToList();
                if (table.SecureView != null)
                {
                    if (table.SecureView.Columns.Count == 0)
                    {
                        DBObjectManager.RefreshColumns(table.SecureView);
                    }
                    m_list = table.SecureView.Columns.ToList();
                }
            }
            else if (context.Instance is DBView)
            {
                var view = context.Instance as DBView;
                m_list = view.Columns.ToList();
            }
            else if (context.Instance is DBColumn && (context.Instance as DBObject).Parent is IContainsColumns)
            {
                var table = (context.Instance as DBObject).Parent as IContainsColumns;
                if (table != null)
                {
                    m_list = table.Columns.ToList();
                }
            }
            else if (context.Instance is RowAction && (context.Instance as RowAction).Table is IContainsColumns)
            {
                var table = (context.Instance as RowAction).Table as IContainsColumns;
                if (table != null)
                {
                    m_list = table.Columns.ToList();
                }
            }
            else if (context.Instance is SecurityPolicyQuestion)
            {
                var question           = context.Instance as SecurityPolicyQuestion;
                var additional_columns = question.Table.AdditionalRelatedColumns.Select(rc => rc.Column).ToList();
                m_list = additional_columns;
            }
            else if (context.Instance is AdditionalColumn)
            {
                var db_rel_col = context.Instance as AdditionalColumn;
                if (db_rel_col.Constraint == null)
                {
                    m_list = db_rel_col.CurrentTable.Columns.ToList();
                }
                else if (db_rel_col.Constraint.Parent == db_rel_col.CurrentTable)
                {
                    m_list = (db_rel_col.Constraint.ReferenceColumn.Parent as DBTable).CombinedColumns.ToList();
                }
                else
                {
                    m_list = (db_rel_col.Constraint.Parent as DBTable).CombinedColumns.ToList();
                }
            }
            else if (context.Instance is Workflow)
            {
                var wf = context.Instance as Workflow;
                if (wf.Table != null && context.PropertyDescriptor.Name == "StateColumn")
                {
                    m_list = wf.Table.ForeignKeys.Select(x => x.Column).Distinct().ToList();
                }
                else if (wf.Table != null && context.PropertyDescriptor.Name == "StateNameColumn" && wf.StateColumn != null)
                {
                    m_list = (wf.Table.ForeignKeys.Where(x => x.Column == wf.StateColumn).FirstOrDefault().ReferenceColumn.Parent as DBTable).Columns.Distinct().ToList();
                }
            }
            else if (context.Instance is SQLUpdateColumnValuePair)
            {
                var cvp = context.Instance as SQLUpdateColumnValuePair;
                if (cvp.Table != null)
                {
                    m_list = cvp.Table.Columns.ToList();
                }
            }
            else if (context.Instance is SQLInsertColumnValuePair)
            {
                var cvp = context.Instance as SQLInsertColumnValuePair;
                if (cvp.Table != null)
                {
                    if (context.PropertyDescriptor.Name == "SourceColumn")
                    {
                        m_list = cvp.Table.Columns.ToList();
                    }
                    else if (cvp.TargetTable != null && context.PropertyDescriptor.Name == "TargetColumn")
                    {
                        m_list = cvp.TargetTable.Columns.ToList();
                    }
                }
            }
            else if (context.Instance is SQLStatement)
            {
                var cvp = context.Instance as SQLStatement;
                if (cvp.Table != null)
                {
                    m_list = cvp.Table.Columns.ToList();
                }
            }

            return(true);
        }