当前位置:Gxlcms > 数据库问题 > lmdb的一些库相关函数

lmdb的一些库相关函数

时间:2021-07-01 10:21:17 帮助过:48人阅读

mdb_env_open ( MDB_env * env, const char * path, unsigned int flags, mdb_mode_t mode )

它的作用是:打开一个环境handle。

注:如果函数失败,我们要调用 mdb_env_close() 来丢弃  MDB_env handle.

参数说明:

[in] env :就是我们的环境handle。

[in] path :数据的路径。注意:它必须存在,并且可写;

[in] flags: 对于环境的一些特别的选项,它必须被设为0 或着把不同的选项 or在一起,

       常见的flag:http://104.237.133.194/doc/ group__mdb.html#ga32a193c6bf4d7d5c5d579e71f22e9340

[in] mode:对于linux来说 ,就是这个操作的对于文件权限(如:0644),windows忽略;

返回值:如果错误,返回一个非零的值,如果正确,返回零;

 

函数 :mdb_env_close ()

void mdb_env_close ( MDB_env * env)

作用:Close the environment and release the memory map.

 

函数: int mdb_env_set_mapsize()

  1. <span style="color: #0000ff">int</span> mdb_env_set_mapsize ( MDB_env *<span style="color: #000000"> env,
  2. size_t size
  3. )</span>

作用:设置环境的memory map 的大小;注意:默认大小 为:10485760 bytes,该函数用在mdb_env_create()之后,且mdb_env_open()之前,当然,在后面它也可能被调用的;

返回值:如果错误,返回一个非零的值,如果正确,返回零;

 

 

函数:int mdb_txn_begin()

  1. <span style="color: #0000ff">int</span> mdb_txn_begin ( MDB_env *<span style="color: #000000"> env,
  2. MDB_txn </span>*<span style="color: #000000"> parent,
  3. unsigned </span><span style="color: #0000ff">int</span><span style="color: #000000"> flags,
  4. MDB_txn </span>**<span style="color: #000000"> txn
  5. )</span>

 

作用:Create a transaction for use with the environment.

参数:[in] env:An environment handle returned by mdb_env_create() 

         [in] parent:可以为空,即NULL,如果不是空的话,the new transaction will be a nested transaction。

         [in] flags: 指对于操作来说一些特别的选项,可以为0或着其它:如MDB_RDONLY,表示:它不会执行任何写操作;

        [in] txn  ,Address where the new MDB_txn handle will be stored .

返回值:如果错误,返回一个非零的值,如果正确,返回零;

另外:The transaction handle may be discarded using mdb_txn_abort() or mdb_txn_commit().

 

函数:mdb_dbi_open()

  1. <span style="color: #0000ff">int</span> mdb_dbi_open ( MDB_txn *<span style="color: #000000"> txn,
  2. </span><span style="color: #0000ff">const</span> <span style="color: #0000ff">char</span> *<span style="color: #000000"> name,
  3. unsigned </span><span style="color: #0000ff">int</span><span style="color: #000000"> flags,
  4. MDB_dbi </span>*<span style="color: #000000"> dbi
  5. )</span>

 

作用:在环境里打开一个database;

注意:database handle denotes the name and parameters of a database, independently of whether such a database exists.The database handle may be discarded by calling mdb_dbi_close().

参数:

[in] txn :A transaction 的handle;

[in]  name:打开的database的名字,If only a single database is needed in the environment, this value may be NULL.

[in]  flags:Special options for this database. 可以为0或着其它选项

[out] dbi :Address where the new MDB_dbi handle will be store;

返回值:如果错误,返回一个非零的值,如果正确,返回零;

 

函数:int mdb_put()

  1. <span style="color: #0000ff">int</span> mdb_put ( MDB_txn *<span style="color: #000000"> txn,
  2. MDB_dbi dbi,
  3. MDB_val </span>*<span style="color: #000000"> key,
  4. MDB_val </span>*<span style="color: #000000"> data,
  5. unsigned </span><span style="color: #0000ff">int</span><span style="color: #000000"> flags
  6. )</span>

作用:store items into a datagase,也就是说,把key/data pairs存放到database里面。

注意:当键值有相同的时候,The default behavior is to enter the new key/data pair, replacing any previously existing

key if duplicates are disallowed, or adding a duplicate data item if duplicates are allowed 。

参数:

[in] txn: A transaction handle returned by mdb_txn_begin() 
[in] dbi :A database handle returned by mdb_dbi_open() 
[in] key :The key to store in the database 
[in,out] data: The data to store 
[in] flags Special options for this operation. This parameter must be set to 0 or by bitwise OR‘ing together one or more of the values described here.

返回值:如果错误,返回一个非零的值,如果正确,返回零;

 

函数:int mdb_txn_commit()

  1. <span style="color: #0000ff">int</span> mdb_txn_commit ( MDB_txn * txn )

作用:提交所有的操作:Commit all the operations of a transaction into the database.

注意:提交完以后,The transaction handle is freed. It and its cursors must not be used again after this call, except with mdb_cursor_renew().

参数:[in] txn:即我们要提交的那个transaction的handle;

返回值:如果错误,返回一个非零的值,如果正确,返回零;

 

函数:int mdb_cursor_open ()

  1. <span style="color: #0000ff">int</span> mdb_cursor_open ( MDB_txn *<span style="color: #000000"> txn,
  2. MDB_dbi dbi,
  3. MDB_cursor </span>**<span style="color: #000000"> cursor
  4. )</span>

作用:创建一个cursor的handle。

备注:A cursor is associated with a specific transaction and database。

参数:

  1. [<span style="color: #0000ff">in</span><span style="color: #000000">] txn A transaction handle returned by mdb_txn_begin()
  2. [</span><span style="color: #0000ff">in</span><span style="color: #000000">] dbi A database handle returned by mdb_dbi_open()
  3. [</span><span style="color: #0000ff">out</span>] cursor Address <span style="color: #0000ff">where</span> the <span style="color: #0000ff">new</span> MDB_cursor handle will be stored

返回值:如果错误,返回一个非零的值,如果正确,返回零;

 

函数:mdb_cursor_get()

  1. <span style="color: #0000ff">int</span> mdb_cursor_get ( MDB_cursor *<span style="color: #000000"> cursor,
  2. MDB_val </span>*<span style="color: #000000"> key,
  3. MDB_val </span>*<span style="color: #000000"> data,
  4. MDB_cursor_op op
  5. )</span>

功能:通过cursor恢复数据

参数:

  1. [<span style="color: #0000ff">in</span><span style="color: #000000">] cursor: A cursor handle returned by mdb_cursor_open()
  2. [</span><span style="color: #0000ff">in</span>,<span style="color: #0000ff">out</span>] key: The key <span style="color: #0000ff">for</span><span style="color: #000000"> a retrieved item
  3. [</span><span style="color: #0000ff">in</span>,<span style="color: #0000ff">out</span><span style="color: #000000">] data: The data of a retrieved item
  4. [</span><span style="color: #0000ff">in</span>] op: A cursor operation MDB_cursor_op

其中:enum MDB_cursor_op,它枚举了许多Cursor Get 的操作,如下所示:

  1. <span style="color: #000000">MDB_FIRST
  2. Position at first key</span>/<span style="color: #000000">data item
  3. MDB_FIRST_DUP
  4. Position at first data item of current key. Only </span><span style="color: #0000ff">for</span><span style="color: #000000"> MDB_DUPSORT
  5. MDB_GET_BOTH
  6. Position at key</span>/data pair. Only <span style="color: #0000ff">for</span><span style="color: #000000"> MDB_DUPSORT
  7. MDB_GET_BOTH_RANGE
  8. position at key, nearest data. Only </span><span style="color: #0000ff">for</span><span style="color: #000000"> MDB_DUPSORT
  9. MDB_GET_CURRENT
  10. Return key</span>/<span style="color: #000000">data at current cursor position
  11. MDB_GET_MULTIPLE
  12. Return key and up to a page of duplicate data items </span><span style="color: #0000ff">from</span> current cursor position. Move cursor to prepare <span style="color: #0000ff">for</span> MDB_NEXT_MULTIPLE. Only <span style="color: #0000ff">for</span><span style="color: #000000"> MDB_DUPFIXED
  13. MDB_LAST
  14. Position at last key</span>/<span style="color: #000000">data item
  15. MDB_LAST_DUP
  16. Position at last data item of current key. Only </span><span style="color: #0000ff">for</span><span style="color: #000000"> MDB_DUPSORT
  17. MDB_NEXT
  18. Position at next data item
  19. MDB_NEXT_DUP
  20. Position at next data item of current key. Only </span><span style="color: #0000ff">for</span><span style="color: #000000"> MDB_DUPSORT
  21. MDB_NEXT_MULTIPLE
  22. Return key and up to a page of duplicate data items </span><span style="color: #0000ff">from</span> next cursor position. Move cursor to prepare <span style="color: #0000ff">for</span> MDB_NEXT_MULTIPLE. Only <span style="color: #0000ff">for</span><span style="color: #000000"> MDB_DUPFIXED
  23. MDB_NEXT_NODUP
  24. Position at first data item of next key
  25. MDB_PREV
  26. Position at previous data item
  27. MDB_PREV_DUP
  28. Position at previous data item of current key. Only </span><span style="color: #0000ff">for</span><span style="color: #000000"> MDB_DUPSORT
  29. MDB_PREV_NODUP
  30. Position at last data item of previous key
  31. MDB_SET
  32. Position at specified key
  33. MDB_SET_KEY
  34. Position at specified key, </span><span style="color: #0000ff">return</span> key +<span style="color: #000000"> data
  35. MDB_SET_RANGE
  36. Position at first key greater than or equal to specified key.</span>

先写到这里吧。。

看的时候,可以结合一个例子:http://blog.csdn.net/u012235274/article/details/51899598

还有很多:http://104.237.133.194/doc/index.html

lmdb的一些库相关函数

标签:after   bottom   ted   duplicate   address   base   相关   eth   路径   

人气教程排行