Пример #1
0
        /// <summary>
        /// Populates the relation ships.
        /// </summary>
        /// <param name="results">The results.</param>
        /// <param name="reader">The reader.</param>
        private static void PopulateRelationShips(List <DbRelationShip> results, SqlDataReader reader)
        {
            while (reader.Read())
            {
                string         constraintName = reader["FK_NAME"].ToString();
                DbRelationShip relation       =
                    results.Find(delegate(DbRelationShip fk) { return(fk.Name == constraintName); });

                if (relation == null)
                {
                    relation      = new DbRelationShip();
                    relation.Name = constraintName;
                    results.Add(relation);
                }

                if (relation.SourceTableName == null)
                {
                    relation.SourceTableName  = reader["FKTABLE_NAME"].ToString();
                    relation.SourceTableOwner = reader["FKTABLE_OWNER"].ToString();
                }

                relation.SourceColumnNames.Add(reader["FKCOLUMN_NAME"].ToString());

                if (relation.TargetTableName == null)
                {
                    relation.TargetTableName  = reader["PKTABLE_NAME"].ToString();
                    relation.TargetTableOwner = reader["PKTABLE_OWNER"].ToString();
                }

                relation.TargetColumnNames.Add(reader["PKCOLUMN_NAME"].ToString());
            }
        }
Пример #2
0
        /// <summary>
        /// Populates the relation ships.
        /// </summary>
        /// <param name="results">The results.</param>
        /// <param name="command">The command.</param>
        private void PopulateRelationShips(List <DbRelationShip> results, OracleCommand command)
        {
            using (OracleDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    string         constraintName = reader["ConstraintName"].ToString();
                    DbRelationShip relation       = results.Find(delegate(DbRelationShip fk) { return(fk.Name == constraintName); });
                    if (relation == null)
                    {
                        relation      = new DbRelationShip();
                        relation.Name = constraintName;
                        results.Add(relation);
                    }

                    if (relation.SourceTableName == null)
                    {
                        relation.SourceTableName  = reader["SourceTable"].ToString();
                        relation.SourceTableOwner = reader["SourceOwner"].ToString();
                    }

                    relation.SourceColumnNames.Add(reader["SourceCol"].ToString());
                    if (relation.TargetTableName == null)
                    {
                        relation.TargetTableOwner = reader["TargetOwner"].ToString();
                        relation.TargetTableName  = reader["TargetTable"].ToString();
                    }
                    RetrieveTargetColumns(connection, relation, reader["RefConstraintName"].ToString());
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Counts the same relations.
        /// </summary>
        /// <param name="relations">The relations.</param>
        /// <param name="relation">The relation.</param>
        /// <returns></returns>
        private static int CountSameRelations(List <DbRelationShip> relations, DbRelationShip relation)
        {
            int nb = 0;

            foreach (DbRelationShip rel in relations)
            {
                if (rel.TargetTableName == relation.TargetTableName && rel.SourceTableName == relation.SourceTableName)
                {
                    nb++;
                }
            }
            return(nb);
        }
Пример #4
0
        /// <summary>
        /// Retrieves the target columns.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="relation">The relation.</param>
        /// <param name="refConstraintName">Name of the ref constraint.</param>
        private void RetrieveTargetColumns(IDbConnection connection, DbRelationShip relation, string refConstraintName)
        {
            OracleCommand command = new OracleCommand();

            command.CommandType = CommandType.Text;
            command.CommandText = @"SELECT     BATCH.TABLE_NAME, COL.COLUMN_NAME as ColName
                FROM         SYS.ALL_CONSTRAINTS BATCH, SYS.ALL_CONS_COLUMNS COL
                WHERE     BATCH.CONSTRAINT_NAME = COL.CONSTRAINT_NAME AND BATCH.OWNER = COL.OWNER AND (BATCH.OWNER = :pOwner) AND 
                      (BATCH.CONSTRAINT_TYPE = 'P') AND (BATCH.TABLE_NAME = :pTable) AND (BATCH.CONSTRAINT_NAME = :ConstraintName)";
            command.Connection  = connection as OracleConnection;

            OracleParameter parm = new OracleParameter("pOwner", OracleType.VarChar, 128);

            parm.Value = relation.TargetTableOwner;
            command.Parameters.Add(parm);
            parm       = new OracleParameter("pTable", OracleType.VarChar, 128);
            parm.Value = relation.TargetTableName;
            command.Parameters.Add(parm);
            parm       = new OracleParameter("ConstraintName", OracleType.VarChar, 128);
            parm.Value = refConstraintName;
            command.Parameters.Add(parm);

            OracleDataReader reader = command.ExecuteReader();

            try
            {
                while (reader.Read())
                {
                    relation.TargetColumnNames.Add(reader["ColName"].ToString());
                }
            }
            finally
            {
                reader.Close();
            }
        }