Esempio n. 1
0
 public override ISchemaBase Clone(ISchemaBase parent)
 {
     Index index = new Index(parent)
                       {
                           AllowPageLocks = this.AllowPageLocks,
                           AllowRowLocks = this.AllowRowLocks,
                           Columns = this.Columns.Clone(),
                           FillFactor = this.FillFactor,
                           FileGroup = this.FileGroup,
                           Id = this.Id,
                           IgnoreDupKey = this.IgnoreDupKey,
                           IsAutoStatistics = this.IsAutoStatistics,
                           IsDisabled = this.IsDisabled,
                           IsPadded = this.IsPadded,
                           IsPrimaryKey = this.IsPrimaryKey,
                           IsUniqueKey = this.IsUniqueKey,
                           Name = this.Name,
                           SortInTempDb = this.SortInTempDb,
                           Status = this.Status,
                           Type = this.Type,
                           Owner = this.Owner,
                           FilterDefintion = this.FilterDefintion
                       };
     ExtendedProperties.ForEach(item => index.ExtendedProperties.Add(item));
     return index;
 }
Esempio n. 2
0
 /// <summary>
 /// Compara dos indices y devuelve true si son iguales, caso contrario, devuelve false.
 /// </summary>
 public static Boolean Compare(Index origen, Index destino)
 {
     if (destino == null) throw new ArgumentNullException("destino");
     if (origen == null) throw new ArgumentNullException("origen");
     if (origen.AllowPageLocks != destino.AllowPageLocks) return false;
     if (origen.AllowRowLocks != destino.AllowRowLocks) return false;
     if (origen.FillFactor != destino.FillFactor) return false;
     if (origen.IgnoreDupKey != destino.IgnoreDupKey) return false;
     if (origen.IsAutoStatistics != destino.IsAutoStatistics) return false;
     if (origen.IsDisabled != destino.IsDisabled) return false;
     if (origen.IsPadded != destino.IsPadded) return false;
     if (origen.IsPrimaryKey != destino.IsPrimaryKey) return false;
     if (origen.IsUniqueKey != destino.IsUniqueKey) return false;
     if (origen.Type != destino.Type) return false;
     if (origen.SortInTempDb != destino.SortInTempDb) return false;
     if (!origen.FilterDefintion.Equals(destino.FilterDefintion)) return false;
     if (!IndexColumns.Compare(origen.Columns, destino.Columns)) return false;
     return CompareFileGroup(origen,destino);
 }
Esempio n. 3
0
 private static Boolean CompareFileGroup(Index origen, Index destino)
 {
     if (destino == null) throw new ArgumentNullException("destino");
     if (origen == null) throw new ArgumentNullException("origen");
     if (origen.FileGroup != null)
     {
         if (!origen.FileGroup.Equals(destino.FileGroup)) return false;
     }
     return true;
 }
Esempio n. 4
0
        public void Fill(Database database, string connectionString)
        {
            int indexid = 0;
            int parentId = 0;
            bool change = false;
            string type;
            ISchemaBase parent = null;
            root.RaiseOnReading(new ProgressEventArgs("Reading Index...", Constants.READING_INDEXES));                      
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand(IndexSQLCommand.Get(database.Info.Version), conn))
                {
                    conn.Open();
                    command.CommandTimeout = 0;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        Index item = null;
                        while (reader.Read())
                        {
                            root.RaiseOnReadingOne(reader["Name"]);
                            type = reader["ObjectType"].ToString().Trim();
                            if (parentId != (int)reader["object_id"])
                            {
                                parentId = (int)reader["object_id"];
                                if (type.Equals("V"))
                                    parent = database.Views.Find(parentId);
                                else
                                    parent = database.Tables.Find(parentId);
                                change = true;
                            }
                            else
                                change = false;
                            if ((indexid != (int)reader["Index_id"]) || (change))
                            {
                                item = new Index(parent);
                                item.Name = reader["Name"].ToString();
                                item.Owner = parent.Owner;
                                item.Type = (Index.IndexTypeEnum)(byte)reader["type"];
                                item.Id = (int)reader["Index_id"];
                                item.IgnoreDupKey = (bool)reader["ignore_dup_key"];
                                item.IsAutoStatistics = (bool)reader["NoAutomaticRecomputation"];
                                item.IsDisabled = (bool)reader["is_disabled"];
                                item.IsPrimaryKey = (bool)reader["is_primary_key"];
                                item.IsUniqueKey = (bool)reader["is_unique"];
                                if (database.Options.Ignore.FilterIndexRowLock)
                                {
                                    item.AllowPageLocks = (bool)reader["allow_page_locks"];
                                    item.AllowRowLocks = (bool)reader["allow_row_locks"];
                                }
                                if (database.Options.Ignore.FilterIndexFillFactor)
                                {
                                    item.FillFactor = (byte)reader["fill_factor"];
                                    item.IsPadded = (bool)reader["is_padded"];
                                }
                                if ((database.Options.Ignore.FilterTableFileGroup) && (item.Type != Index.IndexTypeEnum.XML))
                                    item.FileGroup = reader["FileGroup"].ToString();

                                if ((database.Info.Version == DatabaseInfo.VersionTypeEnum.SQLServer2008) && (database.Options.Ignore.FilterIndexFilter))
                                {
                                    item.FilterDefintion = reader["FilterDefinition"].ToString();
                                }
                                indexid = (int)reader["Index_id"];
                                if (type.Equals("V"))
                                    ((View)parent).Indexes.Add(item);
                                else
                                    ((Table)parent).Indexes.Add(item);
                            }
                            IndexColumn ccon = new IndexColumn(item.Parent);
                            ccon.Name = reader["ColumnName"].ToString();
                            ccon.IsIncluded = (bool)reader["is_included_column"];
                            ccon.Order = (bool)reader["is_descending_key"];
                            ccon.Id = (int)reader["column_id"];
                            ccon.KeyOrder = (byte)reader["key_ordinal"];
                            ccon.DataTypeId = (int)reader["user_type_id"];
                            if ((!ccon.IsIncluded) || (ccon.IsIncluded && database.Options.Ignore.FilterIndexIncludeColumns))
                                item.Columns.Add(ccon);
                        }
                    }
                }
            }
        }