Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include "lmdb.h"
- #include <unistd.h>
- typedef struct param param;
- typedef long long int i64;
- typedef unsigned int u32;
- struct param
- {
- MDB_dbi pagesdb;
- // MDB_dbi testdb;
- MDB_env *env;
- MDB_txn *wtxn;
- MDB_cursor *cursorPages;
- };
- static MDB_txn* open_wtxn(param *data)
- {
- if (mdb_txn_begin(data->env, NULL, 0, &data->wtxn) != MDB_SUCCESS)
- return NULL;
- if (mdb_dbi_open(data->wtxn, "pages", MDB_CREATE | MDB_DUPSORT, &data->pagesdb) != MDB_SUCCESS)
- return NULL;
- if (mdb_cursor_open(data->wtxn, data->pagesdb, &data->cursorPages) != MDB_SUCCESS)
- return NULL;
- return data->wtxn;
- }
- int main(int argc, char* argv[])
- {
- param data;
- // FILE *f;
- char buf1[5000];
- char buf2[5000];
- MDB_val k = {12,buf1};
- MDB_val v = {4063,buf2};
- int rc;
- memset(&data, 0, sizeof(param));
- unlink("lmdbdb");
- unlink("lmdbdb-lock");
- if (mdb_env_create(&data.env) != MDB_SUCCESS)
- return 0;
- if (mdb_env_set_maxdbs(data.env,5) != MDB_SUCCESS)
- return 0;
- if (mdb_env_open(data.env, "lmdbdb", MDB_NOSUBDIR, 0664) != MDB_SUCCESS)
- return 0;
- if (open_wtxn(&data) == NULL)
- return 0;
- if (mdb_txn_commit(data.wtxn) != MDB_SUCCESS)
- return 0;
- if (open_wtxn(&data) == NULL)
- return 0;
- printf("maxkeysize=%d\n",mdb_env_get_maxkeysize(data.env));
- printf("writing keysize=%ld, datasize=%ld\n",k.mv_size, v.mv_size);
- if ((rc = mdb_cursor_put(data.cursorPages,&k,&v,0)) != MDB_SUCCESS)
- {
- printf("Cursor put eror=%d\n",rc);
- }
- mdb_txn_commit(data.wtxn);
- mdb_env_close(data.env);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement