/// <summary> /// Drop index and release slot for another index /// </summary> public bool DropIndex(string field) { if (string.IsNullOrEmpty(field)) { throw new ArgumentNullException("field"); } if (field == "_id") { throw LiteException.IndexDropId(); } // start transaction this.Database.Transaction.Begin(); try { var col = this.GetCollectionPage(false); // if collection not exists, no drop if (col == null) { this.Database.Transaction.Abort(); return(false); } // search for index reference var index = col.GetIndex(field); if (index == null) { this.Database.Transaction.Abort(); return(false); } // delete all data pages + indexes pages this.Database.Indexer.DropIndex(index); // clear index reference index.Clear(); // save collection page col.IsDirty = true; this.Database.Transaction.Commit(); return(true); } catch { this.Database.Transaction.Rollback(); throw; } }
/// <summary> /// Drop an index from a collection /// </summary> public bool DropIndex(string collection, string field) { if (collection.IsNullOrWhiteSpace()) { throw new ArgumentNullException("collection"); } if (field.IsNullOrWhiteSpace()) { throw new ArgumentNullException("field"); } if (field == "_id") { throw LiteException.IndexDropId(); } return(this.Transaction <bool>(collection, false, (col) => { // no collection, no index if (col == null) { return false; } // search for index reference var index = col.GetIndex(field); // no index, no drop if (index == null) { return false; } _log.Write(LoggerWrap.COMMAND, "drop index on '{0}' :: '{1}'", collection, field); // delete all data pages + indexes pages _indexer.DropIndex(index); // clear index reference index.Clear(); // mark collection page as dirty _pager.SetDirty(col); return true; })); }
/// <summary> /// Drop an index from a collection /// </summary> public bool DropIndex(string colName, string field) { if (field == "_id") { throw LiteException.IndexDropId(); } return(Transaction(colName, false, col => { // no collection, no index if (col == null) { return false; } // mark collection page as dirty before changes _pager.SetDirty(col); // search for index reference var index = col.GetIndex(field); // no index, no drop if (index == null) { return false; } _log.Write(Logger.COMMAND, "drop index on '{0}' :: '{1}'", colName, field); // delete all data pages + indexes pages _indexer.DropIndex(index); // clear index reference index.Clear(); return true; })); }