Skip to content

Instantly share code, notes, and snippets.

@rouzier rouzier/mdb_cursor_crash_prev Secret
Last active Aug 29, 2015

Embed
What would you like to do?
mdb_cursor_crash_prev
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <lmdb.h>
int main(void)
{
int r;
MDB_env *env;
MDB_dbi dbi;
MDB_txn *txn;
MDB_val key, val;
MDB_cursor *cur;
unlink("test.mdb");
unlink("test.mdb-lock");
r = 0;
assert( (r = mdb_env_create(&env)) == 0);
assert( (r = mdb_env_open(env, "test.mdb", MDB_NOSUBDIR, 0666)) == 0 );
assert( (r = mdb_txn_begin(env, NULL, 0, &txn)) == 0 );
assert( (r = mdb_dbi_open(txn, NULL, 0, &dbi)) == 0 );
assert( (r = mdb_txn_commit(txn)) == 0);
assert( (r = mdb_txn_begin(env, NULL, 0, &txn)) == 0) ;
key.mv_data = "foo";
key.mv_size = 4;
val.mv_data = "bar";
val.mv_size = 4;
assert( (r = mdb_put(txn, dbi, &key, &val, 0)) == 0);
key.mv_data = "this";
key.mv_size = 5;
val.mv_data = "that";
val.mv_size = 5;
assert( (r = mdb_put(txn, dbi, &key, &val, 0)) == 0);
assert( (r = mdb_txn_commit(txn)) == 0);
assert( (r = mdb_txn_begin(env, NULL, 0, &txn)) == 0);
assert( (r = mdb_cursor_open(txn, dbi, &cur)) == 0);
r = mdb_cursor_get(cur,&key,&val, MDB_LAST);
while(r == 0) {
printf("%s => %s\n", (char*)key.mv_data, (char*)val.mv_data);
assert (mdb_cursor_del(cur, 0) == 0);
r = mdb_cursor_get(cur,&key,&val, MDB_PREV);
}
assert (r == MDB_NOTFOUND);
mdb_cursor_close(cur);
assert( (r = mdb_txn_commit(txn)) == 0);
mdb_env_close(env);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.