1 /* sample-mdb.txt - MDB toy/sample
3 * Do a line-by-line comparison of this and sample-bdb.txt
6 * Copyright 2012-2015 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 /* Note: Most error checking omitted for simplicity */
32 rc = mdb_env_create(&env);
33 rc = mdb_env_open(env, "./testdb", 0, 0664);
34 rc = mdb_txn_begin(env, NULL, 0, &txn);
35 rc = mdb_dbi_open(txn, NULL, 0, &dbi);
37 key.mv_size = sizeof(int);
39 data.mv_size = sizeof(sval);
42 sprintf(sval, "%03x %d foo bar", 32, 3141592);
43 rc = mdb_put(txn, dbi, &key, &data, 0);
44 rc = mdb_txn_commit(txn);
46 fprintf(stderr, "mdb_txn_commit: (%d) %s\n", rc, mdb_strerror(rc));
49 rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
50 rc = mdb_cursor_open(txn, dbi, &cursor);
51 while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
52 printf("key: %p %.*s, data: %p %.*s\n",
53 key.mv_data, (int) key.mv_size, (char *) key.mv_data,
54 data.mv_data, (int) data.mv_size, (char *) data.mv_data);
56 mdb_cursor_close(cursor);
59 mdb_dbi_close(env, dbi);