예제 #1
0
 protected Constraint(ObjectName name, Table table, ConstraintType constraintType, IEnumerable<Column> keyColumns)
 {
     _name = name;
     _table = table;
     _constraintType = constraintType;
     _keyColumns = new List<Column>(keyColumns);
 }
예제 #2
0
 public override void BeginTableVisit(Table table)
 {
     foreach (Rule rule in _rules)
     {
         _report.SetCurrentRule(rule);
         rule.CheckTable(_report, table);
     }
 }
 internal ForeignKeyConstraint(ObjectName name, Table table, ConstraintType constraintType, IEnumerable<Column> keyColumns,
     TableConstraint uniqueConstraint, ForeignKeyRule updateRule, ForeignKeyRule deleteRule, bool? isDisabled)
     : base(name, table, constraintType, keyColumns)
 {
     _uniqueConstraint = uniqueConstraint;
     _updateRule = updateRule;
     _deleteRule = deleteRule;
     _isDisabled = isDisabled;
 }
예제 #4
0
        public Column(Table table, string name, int ordinalPosition, string columnDefault, 
            bool isNullable, string dataType, int? characterMaximumLength, int? characterOctetLength,
            int? numericPrecision, int? numericPrecisionRadix, int? numericScale,
            int? datetimePrecision, string collationName)
        {
            _table = table;

            _name = name;
            _parsedName = new ParsedIdentifier(name);

            _ordinalPosition = ordinalPosition;
            _columnDefault = columnDefault;
            _isNullable = isNullable;
            _dataType = dataType;
            _characterMaximumLength = characterMaximumLength;
            _characterOctetLength = characterOctetLength;
            _numericPrecision = numericPrecision;
            _numericPrecisionRadix = numericPrecisionRadix;
            _numericScale = numericScale;
            _datetimePrecision = datetimePrecision;
            _collationName = collationName;
        }
예제 #5
0
        internal static IEnumerable<Column> ResolveColumns(IEnumerable<string> columnNames, Table table)
        {
            List<Column> columns = new List<Column>();

            foreach (string columnName in columnNames)
            {
                if (!table.Columns.ContainsKey(columnName))
                {
                    throw new InvalidOperationException("A column referenced in a constraint does not exist in the table.");
                }

                columns.Add(table.Columns[columnName]);
            }

            return columns;
        }
예제 #6
0
        static IEnumerable<Table> EdgeGetter(Table table)
        {
            foreach (ForeignKeyConstraint constraint in table.ForeignKeyConstraints)
            {
                if (constraint.IsDisabled ?? false) continue;

                yield return constraint.UniqueConstraint.Table;
            }
        }
예제 #7
0
        public static void CreateFilteredDependenciesGraph(Database database, Table startTable, Plan plan)
        {
            Set<Table> visited = new Set<Table>();
            Stack<Table> seen = new Stack<Table>();

            seen.Push(startTable);

            // The relations that, as a precondition of the delete, must not exist:
            while (seen.Count > 0)
            {
                Table table = seen.Pop();

                visited.UnionUpdate(table);

                foreach (ForeignKeyConstraint constraint in table.ForeignKeyDependencies)
                {
                    if (plan.IsConstraintExcludedFromDependencyDiagram(constraint)) continue;

                    if (!visited.Contains(constraint.Table))
                    {
                        seen.Push(constraint.Table);
                    }
                }
            }

            CreateDependenciesGraph(database, visited);
        }
예제 #8
0
 internal TableConstraint(ObjectName name, Table table, ConstraintType constraintType, IEnumerable<Column> keyColumns)
     : base(name, table, constraintType, keyColumns)
 {
     _relatedForeignKeyConstraints = new Dictionary<ObjectName, ForeignKeyConstraint>();
 }
예제 #9
0
 public override void BeginTableVisit(Table table)
 {
     Console.WriteLine(string.Format("    Table {0}.{1}", table.Name.Schema, table.Name.Name));
 }
예제 #10
0
        public static Database FromConnection(SqlConnection connection)
        {
            Database database = null;

            Dictionary<ObjectName, Table> tables = new Dictionary<ObjectName, Table>();

            using (SqlCommand command = new SqlCommand())
            {
                command.Connection = connection;
                command.CommandText =
                    "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES";

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        // Create the database upon reading the first row so that the database name
                        // can be set using the canonical capitalisation.
                        if (database == null) database = new Database(reader.GetString(0));

                        Table table = new Table(database, new ObjectName(reader.GetString(1), reader.GetString(2)));
                        tables[table.Name] = table;
                    }
                }
            }

            foreach (Table table in tables.Values)
            {
                table.LoadColumnsFromDatabase(connection);
            }

            database._tables = tables;
            database._tablesByShortName = new Dictionary<string, Table>();

            foreach (Table table in tables.Values)
            {
                database._tablesByShortName[table.ParsedName.Value] = table;
            }

            Constraint.PopulateTableConstraintsFromConnection(connection, database);

            return database;
        }
예제 #11
0
 public virtual void EndTableVisit(Table table)
 {
 }
예제 #12
0
 public virtual void BeginTableVisit(Table table)
 {
 }
예제 #13
0
 public virtual void CheckTable(ViolationReport report, Table table)
 {
 }