mtest*.c, sample-*.c: Add/note error checks.

incre
Hallvard Furuseth 11 years ago
parent a604948993
commit e2bdd44624
  1. 75
      libraries/liblmdb/mtest.c
  2. 45
      libraries/liblmdb/mtest2.c
  3. 45
      libraries/liblmdb/mtest3.c
  4. 64
      libraries/liblmdb/mtest4.c
  5. 47
      libraries/liblmdb/mtest5.c
  6. 47
      libraries/liblmdb/mtest6.c
  7. 2
      libraries/liblmdb/sample-bdb.c
  8. 2
      libraries/liblmdb/sample-mdb.c

@ -17,6 +17,11 @@
#include <time.h> #include <time.h>
#include "lmdb.h" #include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
#define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
int main(int argc,char * argv[]) int main(int argc,char * argv[])
{ {
int i = 0, j = 0, rc; int i = 0, j = 0, rc;
@ -39,11 +44,11 @@ int main(int argc,char * argv[])
values[i] = random()%1024; values[i] = random()%1024;
} }
rc = mdb_env_create(&env); E(mdb_env_create(&env));
rc = mdb_env_set_mapsize(env, 10485760); E(mdb_env_set_mapsize(env, 10485760));
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664));
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_open(txn, NULL, 0, &dbi); E(mdb_open(txn, NULL, 0, &dbi));
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = sval; key.mv_data = sval;
@ -53,24 +58,24 @@ int main(int argc,char * argv[])
printf("Adding %d values\n", count); printf("Adding %d values\n", count);
for (i=0;i<count;i++) { for (i=0;i<count;i++) {
sprintf(sval, "%03x %d foo bar", values[i], values[i]); sprintf(sval, "%03x %d foo bar", values[i], values[i]);
rc = mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE); if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE))) {
if (rc) {
j++; j++;
data.mv_size = sizeof(sval); data.mv_size = sizeof(sval);
data.mv_data = sval; data.mv_data = sval;
} }
} }
if (j) printf("%d duplicates skipped\n", j); if (j) printf("%d duplicates skipped\n", j);
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_txn_abort(txn); mdb_txn_abort(txn);
@ -79,30 +84,30 @@ int main(int argc,char * argv[])
for (i= count - 1; i > -1; i-= (random()%5)) { for (i= count - 1; i > -1; i-= (random()%5)) {
j++; j++;
txn=NULL; txn=NULL;
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
sprintf(sval, "%03x ", values[i]); sprintf(sval, "%03x ", values[i]);
rc = mdb_del(txn, dbi, &key, NULL); if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
if (rc) {
j--; j--;
mdb_txn_abort(txn); mdb_txn_abort(txn);
} else { } else {
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
} }
} }
free(values); free(values);
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
printf("Cursor last\n"); printf("Cursor last\n");
rc = mdb_cursor_get(cursor, &key, &data, MDB_LAST); E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
@ -112,12 +117,13 @@ int main(int argc,char * argv[])
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
printf("Cursor last/prev\n"); printf("Cursor last/prev\n");
rc = mdb_cursor_get(cursor, &key, &data, MDB_LAST); E(mdb_cursor_get(cursor, &key, &data, MDB_LAST));
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV); E(mdb_cursor_get(cursor, &key, &data, MDB_PREV));
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
@ -125,43 +131,42 @@ int main(int argc,char * argv[])
mdb_txn_abort(txn); mdb_txn_abort(txn);
printf("Deleting with cursor\n"); printf("Deleting with cursor\n");
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_cursor_open(txn, dbi, &cur2); E(mdb_cursor_open(txn, dbi, &cur2));
for (i=0; i<50; i++) { for (i=0; i<50; i++) {
rc = mdb_cursor_get(cur2, &key, &data, MDB_NEXT); if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, MDB_NEXT)))
if (rc)
break; break;
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
rc = mdb_del(txn, dbi, &key, NULL); E(mdb_del(txn, dbi, &key, NULL));
} }
printf("Restarting cursor in txn\n"); printf("Restarting cursor in txn\n");
rc = mdb_cursor_get(cur2, &key, &data, MDB_FIRST); E(mdb_cursor_get(cur2, &key, &data, MDB_FIRST));
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
for (i=0; i<32; i++) { for (i=0; i<32; i++) {
rc = mdb_cursor_get(cur2, &key, &data, MDB_NEXT); if (RES(MDB_NOTFOUND, mdb_cursor_get(cur2, &key, &data, MDB_NEXT)))
if (rc) break; break;
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
} }
mdb_cursor_close(cur2); mdb_cursor_close(cur2);
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
printf("Restarting cursor outside txn\n"); printf("Restarting cursor outside txn\n");
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
rc = mdb_cursor_get(cursor, &key, &data, MDB_FIRST); E(mdb_cursor_get(cursor, &key, &data, MDB_FIRST));
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
for (i=0; i<32; i++) { for (i=0; i<32; i++) {
rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT); if (RES(MDB_NOTFOUND, mdb_cursor_get(cursor, &key, &data, MDB_NEXT)))
if (rc) break; break;
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);

@ -20,6 +20,11 @@
#include <time.h> #include <time.h>
#include "lmdb.h" #include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
#define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
int main(int argc,char * argv[]) int main(int argc,char * argv[])
{ {
int i = 0, j = 0, rc; int i = 0, j = 0, rc;
@ -42,12 +47,12 @@ int main(int argc,char * argv[])
values[i] = random()%1024; values[i] = random()%1024;
} }
rc = mdb_env_create(&env); E(mdb_env_create(&env));
rc = mdb_env_set_mapsize(env, 10485760); E(mdb_env_set_mapsize(env, 10485760));
rc = mdb_env_set_maxdbs(env, 4); E(mdb_env_set_maxdbs(env, 4));
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_open(txn, "id1", MDB_CREATE, &dbi); E(mdb_open(txn, "id1", MDB_CREATE, &dbi));
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = sval; key.mv_data = sval;
@ -57,20 +62,21 @@ int main(int argc,char * argv[])
printf("Adding %d values\n", count); printf("Adding %d values\n", count);
for (i=0;i<count;i++) { for (i=0;i<count;i++) {
sprintf(sval, "%03x %d foo bar", values[i], values[i]); sprintf(sval, "%03x %d foo bar", values[i], values[i]);
rc = mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE); if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NOOVERWRITE)))
if (rc) j++; j++;
} }
if (j) printf("%d duplicates skipped\n", j); if (j) printf("%d duplicates skipped\n", j);
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_txn_abort(txn); mdb_txn_abort(txn);
@ -79,34 +85,35 @@ int main(int argc,char * argv[])
for (i= count - 1; i > -1; i-= (random()%5)) { for (i= count - 1; i > -1; i-= (random()%5)) {
j++; j++;
txn=NULL; txn=NULL;
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
sprintf(sval, "%03x ", values[i]); sprintf(sval, "%03x ", values[i]);
rc = mdb_del(txn, dbi, &key, NULL); if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, NULL))) {
if (rc) {
j--; j--;
mdb_txn_abort(txn); mdb_txn_abort(txn);
} else { } else {
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
} }
} }
free(values); free(values);
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
printf("Cursor prev\n"); printf("Cursor prev\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi); mdb_close(env, dbi);

@ -20,6 +20,11 @@
#include <time.h> #include <time.h>
#include "lmdb.h" #include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
#define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
int main(int argc,char * argv[]) int main(int argc,char * argv[])
{ {
int i = 0, j = 0, rc; int i = 0, j = 0, rc;
@ -45,12 +50,12 @@ int main(int argc,char * argv[])
values[i] = random()%1024; values[i] = random()%1024;
} }
rc = mdb_env_create(&env); E(mdb_env_create(&env));
rc = mdb_env_set_mapsize(env, 10485760); E(mdb_env_set_mapsize(env, 10485760));
rc = mdb_env_set_maxdbs(env, 4); E(mdb_env_set_maxdbs(env, 4));
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi); E(mdb_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi));
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = kval; key.mv_data = kval;
@ -62,20 +67,21 @@ int main(int argc,char * argv[])
if (!(i & 0x0f)) if (!(i & 0x0f))
sprintf(kval, "%03x", values[i]); sprintf(kval, "%03x", values[i]);
sprintf(sval, "%03x %d foo bar", values[i], values[i]); sprintf(sval, "%03x %d foo bar", values[i], values[i]);
rc = mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA); if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA)))
if (rc) j++; j++;
} }
if (j) printf("%d duplicates skipped\n", j); if (j) printf("%d duplicates skipped\n", j);
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_txn_abort(txn); mdb_txn_abort(txn);
@ -84,39 +90,40 @@ int main(int argc,char * argv[])
for (i= count - 1; i > -1; i-= (random()%5)) { for (i= count - 1; i > -1; i-= (random()%5)) {
j++; j++;
txn=NULL; txn=NULL;
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
sprintf(kval, "%03x", values[i & ~0x0f]); sprintf(kval, "%03x", values[i & ~0x0f]);
sprintf(sval, "%03x %d foo bar", values[i], values[i]); sprintf(sval, "%03x %d foo bar", values[i], values[i]);
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = kval; key.mv_data = kval;
data.mv_size = sizeof(sval); data.mv_size = sizeof(sval);
data.mv_data = sval; data.mv_data = sval;
rc = mdb_del(txn, dbi, &key, &data); if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
if (rc) {
j--; j--;
mdb_txn_abort(txn); mdb_txn_abort(txn);
} else { } else {
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
} }
} }
free(values); free(values);
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
printf("Cursor prev\n"); printf("Cursor prev\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi); mdb_close(env, dbi);

@ -20,6 +20,11 @@
#include <time.h> #include <time.h>
#include "lmdb.h" #include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
#define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
int main(int argc,char * argv[]) int main(int argc,char * argv[])
{ {
int i = 0, j = 0, rc; int i = 0, j = 0, rc;
@ -43,12 +48,12 @@ int main(int argc,char * argv[])
values[i] = i*5; values[i] = i*5;
} }
rc = mdb_env_create(&env); E(mdb_env_create(&env));
rc = mdb_env_set_mapsize(env, 10485760); E(mdb_env_set_mapsize(env, 10485760));
rc = mdb_env_set_maxdbs(env, 4); E(mdb_env_set_maxdbs(env, 4));
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_open(txn, "id4", MDB_CREATE|MDB_DUPSORT|MDB_DUPFIXED, &dbi); E(mdb_open(txn, "id4", MDB_CREATE|MDB_DUPSORT|MDB_DUPFIXED, &dbi));
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = kval; key.mv_data = kval;
@ -59,22 +64,23 @@ int main(int argc,char * argv[])
strcpy(kval, "001"); strcpy(kval, "001");
for (i=0;i<count;i++) { for (i=0;i<count;i++) {
sprintf(sval, "%07x", values[i]); sprintf(sval, "%07x", values[i]);
rc = mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA); if (RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA)))
if (rc) j++; j++;
} }
if (j) printf("%d duplicates skipped\n", j); if (j) printf("%d duplicates skipped\n", j);
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
/* there should be one full page of dups now. /* there should be one full page of dups now.
*/ */
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_txn_abort(txn); mdb_txn_abort(txn);
@ -90,28 +96,29 @@ int main(int argc,char * argv[])
data.mv_data = sval; data.mv_data = sval;
sprintf(sval, "%07x", values[3]+1); sprintf(sval, "%07x", values[3]+1);
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA); (void)RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA));
mdb_txn_abort(txn); mdb_txn_abort(txn);
sprintf(sval, "%07x", values[255]+1); sprintf(sval, "%07x", values[255]+1);
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA); (void)RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA));
mdb_txn_abort(txn); mdb_txn_abort(txn);
sprintf(sval, "%07x", values[500]+1); sprintf(sval, "%07x", values[500]+1);
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA); (void)RES(MDB_KEYEXIST, mdb_put(txn, dbi, &key, &data, MDB_NODUPDATA));
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
/* Try MDB_NEXT_MULTIPLE */ /* Try MDB_NEXT_MULTIPLE */
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT_MULTIPLE)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT_MULTIPLE)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_txn_abort(txn); mdb_txn_abort(txn);
j=0; j=0;
@ -119,38 +126,39 @@ int main(int argc,char * argv[])
for (i= count - 1; i > -1; i-= (random()%3)) { for (i= count - 1; i > -1; i-= (random()%3)) {
j++; j++;
txn=NULL; txn=NULL;
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
sprintf(sval, "%07x", values[i]); sprintf(sval, "%07x", values[i]);
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = kval; key.mv_data = kval;
data.mv_size = sizeof(sval); data.mv_size = sizeof(sval);
data.mv_data = sval; data.mv_data = sval;
rc = mdb_del(txn, dbi, &key, &data); if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
if (rc) {
j--; j--;
mdb_txn_abort(txn); mdb_txn_abort(txn);
} else { } else {
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
} }
} }
free(values); free(values);
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
printf("Cursor prev\n"); printf("Cursor prev\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi); mdb_close(env, dbi);

@ -20,6 +20,11 @@
#include <time.h> #include <time.h>
#include "lmdb.h" #include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
#define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
int main(int argc,char * argv[]) int main(int argc,char * argv[])
{ {
int i = 0, j = 0, rc; int i = 0, j = 0, rc;
@ -45,13 +50,13 @@ int main(int argc,char * argv[])
values[i] = random()%1024; values[i] = random()%1024;
} }
rc = mdb_env_create(&env); E(mdb_env_create(&env));
rc = mdb_env_set_mapsize(env, 10485760); E(mdb_env_set_mapsize(env, 10485760));
rc = mdb_env_set_maxdbs(env, 4); E(mdb_env_set_maxdbs(env, 4));
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi); E(mdb_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = kval; key.mv_data = kval;
@ -63,21 +68,22 @@ int main(int argc,char * argv[])
if (!(i & 0x0f)) if (!(i & 0x0f))
sprintf(kval, "%03x", values[i]); sprintf(kval, "%03x", values[i]);
sprintf(sval, "%03x %d foo bar", values[i], values[i]); sprintf(sval, "%03x %d foo bar", values[i], values[i]);
rc = mdb_cursor_put(cursor, &key, &data, MDB_NODUPDATA); if (RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NODUPDATA)))
if (rc) j++; j++;
} }
if (j) printf("%d duplicates skipped\n", j); if (j) printf("%d duplicates skipped\n", j);
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
key.mv_data, (int) key.mv_size, (char *) key.mv_data, key.mv_data, (int) key.mv_size, (char *) key.mv_data,
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_txn_abort(txn); mdb_txn_abort(txn);
@ -86,39 +92,40 @@ int main(int argc,char * argv[])
for (i= count - 1; i > -1; i-= (random()%5)) { for (i= count - 1; i > -1; i-= (random()%5)) {
j++; j++;
txn=NULL; txn=NULL;
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
sprintf(kval, "%03x", values[i & ~0x0f]); sprintf(kval, "%03x", values[i & ~0x0f]);
sprintf(sval, "%03x %d foo bar", values[i], values[i]); sprintf(sval, "%03x %d foo bar", values[i], values[i]);
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = kval; key.mv_data = kval;
data.mv_size = sizeof(sval); data.mv_size = sizeof(sval);
data.mv_data = sval; data.mv_data = sval;
rc = mdb_del(txn, dbi, &key, &data); if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
if (rc) {
j--; j--;
mdb_txn_abort(txn); mdb_txn_abort(txn);
} else { } else {
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
} }
} }
free(values); free(values);
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
printf("Cursor prev\n"); printf("Cursor prev\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi); mdb_close(env, dbi);

@ -20,6 +20,11 @@
#include <time.h> #include <time.h>
#include "lmdb.h" #include "lmdb.h"
#define E(expr) CHECK((rc = (expr)) == MDB_SUCCESS, #expr)
#define RES(err, expr) ((rc = expr) == (err) || (CHECK(!rc, #expr), 0))
#define CHECK(test, msg) ((test) ? (void)0 : ((void)fprintf(stderr, \
"%s:%d: %s: %s\n", __FILE__, __LINE__, msg, mdb_strerror(rc)), abort()))
char dkbuf[1024]; char dkbuf[1024];
int main(int argc,char * argv[]) int main(int argc,char * argv[])
@ -38,14 +43,14 @@ int main(int argc,char * argv[])
srandom(time(NULL)); srandom(time(NULL));
rc = mdb_env_create(&env); E(mdb_env_create(&env));
rc = mdb_env_set_mapsize(env, 10485760); E(mdb_env_set_mapsize(env, 10485760));
rc = mdb_env_set_maxdbs(env, 4); E(mdb_env_set_maxdbs(env, 4));
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
rc = mdb_open(txn, "id6", MDB_CREATE|MDB_INTEGERKEY, &dbi); E(mdb_open(txn, "id6", MDB_CREATE|MDB_INTEGERKEY, &dbi));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
rc = mdb_stat(txn, dbi, &mst); E(mdb_stat(txn, dbi, &mst));
sval = calloc(1, mst.ms_psize / 4); sval = calloc(1, mst.ms_psize / 4);
key.mv_size = sizeof(long); key.mv_size = sizeof(long);
@ -57,27 +62,28 @@ int main(int argc,char * argv[])
for (i=0;i<12;i++) { for (i=0;i<12;i++) {
kval = i*5; kval = i*5;
sprintf(sval, "%08x", kval); sprintf(sval, "%08x", kval);
rc = mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE); (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
} }
printf("Adding 12 more values, should yield 3 splits\n"); printf("Adding 12 more values, should yield 3 splits\n");
for (i=0;i<12;i++) { for (i=0;i<12;i++) {
kval = i*5+4; kval = i*5+4;
sprintf(sval, "%08x", kval); sprintf(sval, "%08x", kval);
rc = mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE); (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
} }
printf("Adding 12 more values, should yield 3 splits\n"); printf("Adding 12 more values, should yield 3 splits\n");
for (i=0;i<12;i++) { for (i=0;i<12;i++) {
kval = i*5+1; kval = i*5+1;
sprintf(sval, "%08x", kval); sprintf(sval, "%08x", kval);
rc = mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE); (void)RES(MDB_KEYEXIST, mdb_cursor_put(cursor, &key, &data, MDB_NOOVERWRITE));
} }
rc = mdb_cursor_get(cursor, &key, &data, MDB_FIRST); E(mdb_cursor_get(cursor, &key, &data, MDB_FIRST));
do { do {
printf("key: %p %s, data: %p %.*s\n", printf("key: %p %s, data: %p %.*s\n",
key.mv_data, mdb_dkey(&key, dkbuf), key.mv_data, mdb_dkey(&key, dkbuf),
data.mv_data, (int) data.mv_size, (char *) data.mv_data); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
} while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0); } while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0);
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_txn_commit(txn); mdb_txn_commit(txn);
@ -87,41 +93,42 @@ int main(int argc,char * argv[])
for (i= count - 1; i > -1; i-= (random()%5)) { for (i= count - 1; i > -1; i-= (random()%5)) {
j++; j++;
txn=NULL; txn=NULL;
rc = mdb_txn_begin(env, NULL, 0, &txn); E(mdb_txn_begin(env, NULL, 0, &txn));
sprintf(kval, "%03x", values[i & ~0x0f]); sprintf(kval, "%03x", values[i & ~0x0f]);
sprintf(sval, "%03x %d foo bar", values[i], values[i]); sprintf(sval, "%03x %d foo bar", values[i], values[i]);
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
key.mv_data = kval; key.mv_data = kval;
data.mv_size = sizeof(sval); data.mv_size = sizeof(sval);
data.mv_data = sval; data.mv_data = sval;
rc = mdb_del(txn, dbi, &key, &data); if (RES(MDB_NOTFOUND, mdb_del(txn, dbi, &key, &data))) {
if (rc) {
j--; j--;
mdb_txn_abort(txn); mdb_txn_abort(txn);
} else { } else {
rc = mdb_txn_commit(txn); E(mdb_txn_commit(txn));
} }
} }
free(values); free(values);
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
rc = mdb_env_stat(env, &mst); E(mdb_env_stat(env, &mst));
rc = mdb_txn_begin(env, NULL, 1, &txn); E(mdb_txn_begin(env, NULL, 1, &txn));
rc = mdb_cursor_open(txn, dbi, &cursor); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
printf("Cursor prev\n"); printf("Cursor prev\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_PREV)) == 0) {
printf("key: %.*s, data: %.*s\n", printf("key: %.*s, data: %.*s\n",
(int) key.mv_size, (char *) key.mv_data, (int) key.mv_size, (char *) key.mv_data,
(int) data.mv_size, (char *) data.mv_data); (int) data.mv_size, (char *) data.mv_data);
} }
CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(txn, dbi); mdb_close(env, dbi);
mdb_txn_abort(txn); mdb_txn_abort(txn);
#endif #endif

@ -28,6 +28,8 @@ int main(int argc,char * argv[])
DBC *cursor; DBC *cursor;
char sval[32], kval[32]; char sval[32], kval[32];
/* Note: Most error checking omitted for simplicity */
#define FLAGS (DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_INIT_MPOOL|DB_CREATE|DB_THREAD) #define FLAGS (DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_INIT_MPOOL|DB_CREATE|DB_THREAD)
rc = db_env_create(&env, 0); rc = db_env_create(&env, 0);
rc = env->open(env, "./testdb", FLAGS, 0664); rc = env->open(env, "./testdb", FLAGS, 0664);

@ -27,6 +27,8 @@ int main(int argc,char * argv[])
MDB_cursor *cursor; MDB_cursor *cursor;
char sval[32]; char sval[32];
/* Note: Most error checking omitted for simplicity */
rc = mdb_env_create(&env); rc = mdb_env_create(&env);
rc = mdb_env_open(env, "./testdb", 0, 0664); rc = mdb_env_open(env, "./testdb", 0, 0664);
rc = mdb_txn_begin(env, NULL, 0, &txn); rc = mdb_txn_begin(env, NULL, 0, &txn);

Loading…
Cancel
Save