public InDbIndexDef AddNewIndexDef(params string[] fieldNames)
        {
            InDbFieldDefs fieldDefs = new InDbFieldDefs(this.FDb);

            foreach (string fieldName in fieldNames)
            {
                fieldDefs.Add(this.FieldDefs[fieldName]);
            }
            return(this.IndexDefs[this.IndexDefs.Add(new InDbIndexDef("", fieldDefs))]);
        }
        private void LoadIndexDefs(InDbTableDef tableDef)
        {
            SqlCommand command = this.Connection.CreateCommand();

            command.CommandText = string.Format("EXEC sp_indexes_rowset @table_name = '{0}', @table_schema = '{1}'", (object)tableDef.Name, (object)this.GetSchemaName());
            Hashtable hashtable = new Hashtable();
            string    str1      = string.Empty;

            using (IDataReader dataReader = (IDataReader)command.ExecuteReader())
            {
                while (dataReader.Read())
                {
                    string str2  = dataReader.GetString(dataReader.GetOrdinal("INDEX_NAME"));
                    string str3  = dataReader.GetString(dataReader.GetOrdinal("COLUMN_NAME"));
                    int    index = dataReader.GetInt32(dataReader.GetOrdinal("ORDINAL_POSITION")) - 1;
                    if (Convert.ToInt32(dataReader.GetValue(dataReader.GetOrdinal("PRIMARY_KEY"))) != 0)
                    {
                        str1 = str2;
                    }
                    StringCollection stringCollection = (StringCollection)hashtable[(object)str2];
                    if (stringCollection == null)
                    {
                        stringCollection = new StringCollection();
                        hashtable.Add((object)str2, (object)stringCollection);
                    }
                    while (index > stringCollection.Count - 1)
                    {
                        stringCollection.Add(string.Empty);
                    }
                    if (stringCollection[index] == str3)
                    {
                        throw new InDbException(string.Format("Столбец {0} входит более одного раза в индекс {1}.", (object)str3, (object)str2));
                    }
                    stringCollection[index] = str3;
                }
            }
            foreach (string key in (IEnumerable)hashtable.Keys)
            {
                StringCollection stringCollection = (StringCollection)hashtable[(object)key];
                string[]         array            = new string[stringCollection.Count];
                stringCollection.CopyTo(array, 0);
                InDbFieldDefs fieldDefs = new InDbFieldDefs((InDbDatabase)this);
                foreach (string name in stringCollection)
                {
                    fieldDefs.Add(tableDef.FieldDefs[name]);
                }
                InDbIndexDef indexDef = new InDbIndexDef(key, fieldDefs);
                tableDef.IndexDefs.Add(indexDef);
                if (key == str1)
                {
                    tableDef.OriginalPrimaryKey = indexDef;
                    tableDef.PrimaryKey         = indexDef;
                }
            }
        }
 internal InDbTableDef(InDbDatabase db, string tableName, bool isNew)
 {
     this.FDb                = db;
     this.FieldDefs          = new InDbFieldDefs(this.FDb);
     this.FFieldDefsToDelete = new InDbFieldDefs(this.FDb);
     this.IndexDefs          = new InDbIndexDefs(this.FDb);
     this.FIndexDefsToDelete = new InDbIndexDefs(this.FDb);
     this.FModifiedIndexDefs = new InDbIndexDefs(this.FDb);
     this.Name               = tableName;
     if (isNew)
     {
         return;
     }
     this.OriginalName = tableName;
 }
Example #4
0
 internal InDbIndexDef(string name, InDbFieldDefs fieldDefs)
 {
     this.FName     = name;
     this.FieldDefs = fieldDefs;
 }