1 /* sample-mdb.c - MDB toy/sample
3 * Do a line-by-line comparison of this and sample-bdb.c
6 * Copyright 2012 Howard Chu, Symas Corp.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
20 int main(int argc,char * argv[])
30 rc = mdb_env_create(&env);
31 rc = mdb_env_open(env, "./testdb", 0, 0664);
32 rc = mdb_txn_begin(env, NULL, 0, &txn);
33 rc = mdb_open(txn, NULL, 0, &dbi);
35 key.mv_size = sizeof(int);
37 data.mv_size = sizeof(sval);
40 sprintf(sval, "%03x %d foo bar", 32, 3141592);
41 rc = mdb_put(txn, dbi, &key, &data, 0);
42 rc = mdb_txn_commit(txn);
44 fprintf(stderr, "mdb_txn_commit: (%d) %s\n", rc, mdb_strerror(rc));
47 rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
48 rc = mdb_cursor_open(txn, dbi, &cursor);
49 while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
50 printf("key: %p %.*s, data: %p %.*s\n",
51 key.mv_data, (int) key.mv_size, (char *) key.mv_data,
52 data.mv_data, (int) data.mv_size, (char *) data.mv_data);
54 mdb_cursor_close(cursor);