public void CreateIndex(string name, Dictionary <string, bool> indexKeys, int density = 100, bool primary = false,
                         bool unique = false)
 {
     CheckState();
     _indexesValid = false;
     EsentIndex.Create(this, name, indexKeys, density, primary, unique);
 }
Ejemplo n.º 2
0
        internal static EsentIndex Create(EsentTable table, string name, Dictionary <string, bool> indexKeys, int density,
                                          bool primary, bool unique)
        {
            var index = new EsentIndex
            {
                Table     = table,
                Name      = name,
                IndexKeys = indexKeys,
                Primary   = primary,
                Unique    = unique
            };
            var count = indexKeys.Count;

            if (count < 1)
            {
                throw new InvalidOperationException("Index needs at least one column!");
            }
            var key = string.Empty;

            for (var i = 0; i < count; i++)
            {
                var c = indexKeys.Keys.ToList()[i];
                key += indexKeys[c] ? '+' : '-';
                key += $"{c}\0";
            }
            key += '\0';
            var option =
                (primary ? CreateIndexGrbit.IndexPrimary : CreateIndexGrbit.None) |
                (unique ? CreateIndexGrbit.IndexUnique : CreateIndexGrbit.None);

            Api.JetCreateIndex(table.Database.Session.JetId, table.JetId, name, option, key, key.Length, density);
            return(index);
        }
 public void DropIndex(string name)
 {
     CheckState();
     _indexesValid = false;
     EsentIndex.Drop(this, name);
 }
 public void SetCurrentIndex(string name)
 {
     CheckState();
     EsentIndex.SetCurrent(this, name);
 }