Esempio n. 1
0
        /// <summary>
        /// Analyses the table.
        /// </summary>
        public void Analyse(IADOConnection conn)
        {
            using (var cmd = conn.CreateCommand())
            {
                StringBuilder query = new StringBuilder();
                query.AppendLine("SELECT  COLUMNPROPERTY(SC.id, name, 'IsIdentity') as [Identity] , * ");
                query.AppendLine("FROM INFORMATION_SCHEMA.COLUMNS i_S ");
                query.AppendLine("Inner Join syscolumns SC on (SC.Name = i_S.COLUMN_NAME) and (OBJECT_NAME(SC.id) = I_S.TABLE_NAME) ");
                query.AppendLine($"Where I_S.TABLE_NAME = '{_name}'");

                cmd.CommandText = query.ToString();
                IDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    DbColumn column = new DbColumn(_name, reader["COLUMN_NAME"].ToString())
                    {
                        IsPrimary  = (Convert.ToInt32(reader["Identity"]) != 0),
                        DataType   = reader["DATA_TYPE"].ToString().ToLower(),
                        IsNullAble = (reader["IS_NULLABLE"].ToString().ToUpper() == "YES"),
                        Length     = reader["CHARACTER_MAXIMUM_LENGTH"] as int? ?? default(int)
                    };
                    _columns.Add(column);
                }
                reader.Close();
                reader = null;

                foreach (var item in _columns)
                {
                    item.Analyse(conn);
                }
            }
        }
Esempio n. 2
0
        public void Analyse(IADOConnection conn)
        {
            using (var cmd = conn.CreateCommand())
            {
                StringBuilder query = new StringBuilder();

                query.AppendLine("SELECT * ");
                query.AppendLine("From INFORMATION_SCHEMA.TABLES ");
                query.AppendLine("Where TABLE_TYPE = 'BASE TABLE'");

                cmd.CommandText = query.ToString();
                IDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    DbTable table = new DbTable(reader["TABLE_NAME"].ToString());
                    if (Name == string.Empty)
                    {
                        Name = reader["TABLE_CATALOG"].ToString();
                    }
                    _tables.Add(table);
                }
                reader.Close();
                reader = null;

                foreach (DbTable table in _tables)
                {
                    table.Analyse(conn);
                }
            }
        }
Esempio n. 3
0
        public void Analyse(IADOConnection conn)
        {
            using (var cmd = conn.CreateCommand())
            {
                StringBuilder query = new StringBuilder();
                query.AppendLine("select CCU.table_name src_table, CCU.constraint_name src_constraint, CCU.column_name src_col, KCU.table_name target_table, KCU.column_name target_col ");
                query.AppendLine("from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU, INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC, INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU ");
                query.AppendLine($"Where CCU.table_name = '{_tableName}' AND CCU.column_name = '{_name}' AND CCU.constraint_name = RC.constraint_name And KCU.constraint_name = RC.unique_constraint_name ");
                query.AppendLine("order by CCU.table_name, CCU.constraint_name ");

                cmd.CommandText = query.ToString();
                IDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    IsForeignKey = true;
                    TargetTable  = reader["target_table"].ToString();
                    TargetColumn = reader["target_col"].ToString();
                }
                reader.Close();
                reader = null;
            }
        }