Advertisement
Guest User

Untitled

a guest
May 27th, 2015
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <fcntl.h>
  5. #include <stdlib.h>
  6. #include "lmdb.h"
  7. #include <unistd.h>
  8.  
  9. typedef struct param param;
  10. typedef long long int i64;
  11. typedef unsigned int u32;
  12.  
  13. struct param
  14. {
  15. MDB_dbi pagesdb;
  16. // MDB_dbi testdb;
  17. MDB_env *env;
  18. MDB_txn *wtxn;
  19. MDB_cursor *cursorPages;
  20. };
  21.  
  22.  
  23. static MDB_txn* open_wtxn(param *data)
  24. {
  25. if (mdb_txn_begin(data->env, NULL, 0, &data->wtxn) != MDB_SUCCESS)
  26. return NULL;
  27. if (mdb_dbi_open(data->wtxn, "pages", MDB_CREATE | MDB_DUPSORT, &data->pagesdb) != MDB_SUCCESS)
  28. return NULL;
  29. if (mdb_cursor_open(data->wtxn, data->pagesdb, &data->cursorPages) != MDB_SUCCESS)
  30. return NULL;
  31.  
  32. return data->wtxn;
  33. }
  34.  
  35.  
  36. int main(int argc, char* argv[])
  37. {
  38. param data;
  39. // FILE *f;
  40. char buf1[5000];
  41. char buf2[5000];
  42. MDB_val k = {12,buf1};
  43. MDB_val v = {4063,buf2};
  44. int rc;
  45.  
  46. memset(&data, 0, sizeof(param));
  47.  
  48. unlink("lmdbdb");
  49. unlink("lmdbdb-lock");
  50.  
  51. if (mdb_env_create(&data.env) != MDB_SUCCESS)
  52. return 0;
  53.  
  54. if (mdb_env_set_maxdbs(data.env,5) != MDB_SUCCESS)
  55. return 0;
  56.  
  57. if (mdb_env_open(data.env, "lmdbdb", MDB_NOSUBDIR, 0664) != MDB_SUCCESS)
  58. return 0;
  59.  
  60. if (open_wtxn(&data) == NULL)
  61. return 0;
  62.  
  63. if (mdb_txn_commit(data.wtxn) != MDB_SUCCESS)
  64. return 0;
  65.  
  66. if (open_wtxn(&data) == NULL)
  67. return 0;
  68.  
  69. printf("maxkeysize=%d\n",mdb_env_get_maxkeysize(data.env));
  70. printf("writing keysize=%ld, datasize=%ld\n",k.mv_size, v.mv_size);
  71. if ((rc = mdb_cursor_put(data.cursorPages,&k,&v,0)) != MDB_SUCCESS)
  72. {
  73. printf("Cursor put eror=%d\n",rc);
  74. }
  75.  
  76.  
  77. mdb_txn_commit(data.wtxn);
  78. mdb_env_close(data.env);
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement