public static void Dump(IntPtr db) { var options = Native.leveldb_readoptions_create(); IntPtr iter = Native.leveldb_create_iterator(db, options); for (Native.leveldb_iter_seek_to_first(iter); Native.leveldb_iter_valid(iter); Native.leveldb_iter_next(iter)) { string key = Native.leveldb_iter_key(iter); string value = Native.leveldb_iter_value(iter); Console.WriteLine("'{0}' => '{1}'", key, value); } Native.leveldb_iter_destroy(iter); }
public void IsValid() { var writeOptions = Native.leveldb_writeoptions_create(); Native.leveldb_put(Database, writeOptions, "key1", "value1"); var readOptions = Native.leveldb_readoptions_create(); IntPtr iter = Native.leveldb_create_iterator(Database, readOptions); Native.leveldb_iter_seek_to_last(iter); Assert.IsTrue(Native.leveldb_iter_valid(iter)); Native.leveldb_iter_next(iter); Assert.IsFalse(Native.leveldb_iter_valid(iter)); }
public IEnumerator <KeyValuePair <string, string> > GetEnumerator() { CheckDisposed(); var options = new ReadOptions(); IntPtr iter = IntPtr.Zero; try { iter = Native.leveldb_create_iterator(Handle, options.Handle); for (Native.leveldb_iter_seek_to_first(iter); Native.leveldb_iter_valid(iter); Native.leveldb_iter_next(iter)) { string key = Native.leveldb_iter_key(iter); string value = Native.leveldb_iter_value(iter); var kvp = new KeyValuePair <string, string>(key, value); yield return(kvp); } } finally { if (iter != IntPtr.Zero) { Native.leveldb_iter_destroy(iter); } } }