lmdb的一些库相关函数

MDB_env 为一个结构体,Opaque structure for a database environment.

MDB_txn :Opaque structure for a transaction handle.

typedef unsigned int MDB_dbi, A handle for an individual database in the DB environment.

struct MDB_val  :Generic structure used for passing keys and data in and out of the database.

它包含:size_t mv_size, void* mv_data;

structure MDB_cursor: Opaque structure for navigating through a database.

函数 int mdb_env_create(MDB_env** env)

它的作用就是创建一个LMDB的环境handle,就是指向一个分配了内存的地址啦,这个函数会为MDB_env结构体分配一个内存。它我们使用handle  的时候,首先要用mdb_env_open()函数打开,最后也要调用mdb_env_close()函数释放掉内存并discard handle。

参数:[out] env,The address where the new handle will be stored。

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

函数 :mdb_env_open()

int 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()

int mdb_env_set_mapsize  ( MDB_env *  env,
                            size_t    size
                          )

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

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

函数:int mdb_txn_begin()

int mdb_txn_begin  ( MDB_env *     env,
                     MDB_txn *     parent,
                     unsigned int  flags,
                     MDB_txn **     txn
                    )

作用: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()

int mdb_dbi_open  ( MDB_txn *  txn,
  const char *  name,
  unsigned int  flags,
  MDB_dbi *  dbi
 )

作用:在环境里打开一个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()

int mdb_put  ( MDB_txn *  txn,
  MDB_dbi  dbi,
  MDB_val *  key,
  MDB_val *  data,
  unsigned int  flags
 )

作用: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()

int 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 ()

int mdb_cursor_open  ( MDB_txn *  txn,
  MDB_dbi  dbi,
  MDB_cursor **  cursor
 )

作用:创建一个cursor的handle。

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

参数:

[in] txn A transaction handle returned by mdb_txn_begin()
[in] dbi A database handle returned by mdb_dbi_open()
[out] cursor Address where the new MDB_cursor handle will be stored

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

函数:mdb_cursor_get()

int mdb_cursor_get  ( MDB_cursor *  cursor,
  MDB_val *  key,
  MDB_val *  data,
  MDB_cursor_op  op
 )

功能:通过cursor恢复数据

参数:

[in] cursor: A cursor handle returned by mdb_cursor_open()
[in,out] key: The key for a retrieved item
[in,out] data: The data of a retrieved item
[in] op: A cursor operation MDB_cursor_op

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

MDB_FIRST
Position at first key/data item 

MDB_FIRST_DUP
Position at first data item of current key. Only for MDB_DUPSORT 

MDB_GET_BOTH
Position at key/data pair. Only for MDB_DUPSORT 

MDB_GET_BOTH_RANGE
position at key, nearest data. Only for MDB_DUPSORT 

MDB_GET_CURRENT
Return key/data at current cursor position 

MDB_GET_MULTIPLE
Return key and up to a page of duplicate data items from current cursor position. Move cursor to prepare for MDB_NEXT_MULTIPLE. Only for MDB_DUPFIXED 

MDB_LAST
Position at last key/data item 

MDB_LAST_DUP
Position at last data item of current key. Only for MDB_DUPSORT 

MDB_NEXT
Position at next data item 

MDB_NEXT_DUP
Position at next data item of current key. Only for MDB_DUPSORT 

MDB_NEXT_MULTIPLE
Return key and up to a page of duplicate data items from next cursor position. Move cursor to prepare for MDB_NEXT_MULTIPLE. Only for MDB_DUPFIXED 

MDB_NEXT_NODUP
Position at first data item of next key 

MDB_PREV
Position at previous data item 

MDB_PREV_DUP
Position at previous data item of current key. Only for MDB_DUPSORT 

MDB_PREV_NODUP
Position at last data item of previous key 

MDB_SET
Position at specified key 

MDB_SET_KEY
Position at specified key, return key + data 

MDB_SET_RANGE
Position at first key greater than or equal to specified key.

先写到这里吧。。

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

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

时间: 2024-08-06 15:42:19

lmdb的一些库相关函数的相关文章

C语言多线程pthread库相关函数说明

线程相关操作说明 一 pthread_t pthread_t在头文件/usr/include/bits/pthreadtypes.h中定义: typedef unsigned long int pthread_t; 它是一个线程的标识符. 二 pthread_create 函数pthread_create用来创建一个线程,它的原型为: extern int pthread_create __P ((pthread_t *__thread, __const pthread_attr_t *__at

gcc编译时对'xxxx'未定义的引用问题

gcc编译时对’xxxx’未定义的引用问题 gcc编译时对’xxxx’未定义的引用问题 原因 解决办法 gcc 依赖顺序问题 在使用gcc编译的时候有时候会碰到这样的问题,编译为.o(obj) 文件没有问题,但是编译(这一步应该是链接)为可执行文件的时候会出现找不到’xxx’的定义的情况. 本文由乌合之众 lym瞎编,欢迎转载blog.cnblogs.net/oloroso 本文由乌合之众 lym瞎编,欢迎转载 my.oschina.net/oloroso 例如: g++ -o spider -

nineoldandroid 详细使用并且实现drawerlayout侧滑动画

nineoldandroid.view.ViewHelpe是一个为了兼容3.0以下的一个动画开源库 相关函数解读:(第一个参数都为动画对象,第二个为动画属性值的变化表达式) ViewHelper.setTranslationX(,);//x方向平移 ViewHelper.setTranslationY(,); ViewHelper.setScaleX(,);x方向变化大小 ViewHelper.setScaleY(,); ViewHelper.setAlpha(,);透明度变化 ViewHelp

Linux网络编程视频 百度网盘

Linux网络编程(总共41集)讲解Linux网络编程知识,分以下四个篇章.Linux网络编程之TCP/IP基础篇Linux网络编程之socket编程篇Linux网络编程之进程间通信篇Linux网络编程之线程篇Linux网络编程之TCP/IP基础篇01TCPIP基础(一)ISO/OSI参考模型TCP/IP四层模型基本概念(对等通信.封装.分用.端口)02TCPIP基础(二)最大传输单元(MTU)/路径MTU以太网帧格式ICMPARPRARP03TCPIP基础(三)IP数据报格式网际校验和路由04

gcc编译时对’xxxx’未定义的引用问题

gcc编译时对'xxxx'未定义的引用问题 原因 解决办法 gcc 依赖顺序问题 在使用gcc编译的时候有时候会碰到这样的问题,编译为.o(obj) 文件没有问题,但是编译(这一步应该是链接)为可执行文件的时候会出现找不到'xxx'的定义的情况. 本文由乌合之众 lym瞎编,欢迎转载blog.cnblogs.net/oloroso本文由乌合之众 lym瞎编,欢迎转载 my.oschina.net/oloroso 例如: g++ -o spider -rdynamic -lpthread -lev

【转】OpenGL相关函数库介绍

原文:http://blog.chinaunix.net/uid-20638550-id-1909182.html OpenGL 函数库相关的API有核心库(gl).实用库(glu).辅助库(aux).实用工具库(glut).窗口库(glx.agl.wgl)和扩展函数库等. 从图1可以看出,gl是核心,glu是对gl的部分封装.glx.agl.wgl 是针对不同窗口系统的函数.glut是为跨平台的OpenGL程序的工具包,比aux功能强大.扩展函数库是硬件厂商为实现硬件更新利用OpenGL的扩

sde空间库的相关函数

1.在sde库中创建表:community 1 表:community 2 字段:id(INTEGER), 3 shape(ST_GEOMETRY) 4 5 脚本如下: 6 create table community( 7 id INTEGER (20) primary key, 8 shape ST_GEOMETRY 9 ); community 2.往sde库中添加资源类型: 1.1点资源: 1 //方式一 2 insert into community (id,shape) values

php数据库操作常用相关函数

MySQL访问函数都需要有相应的权限才能运行.常用的相关函数介绍如下: (1)integer mysql_connect(主机,用户名,口令); 此函数开始一个对指定主机上的MySQL数据库的连接.若该数据库位于一个不同地端口,则在主机名后加上冒号和端口号.所有参数均为可选的,缺省情况下分别对应为本地主机.用户正在执行的脚本名和空.主机可以是IP地址或域名. 在脚本执行结束时,连接被自动关闭,也可以用mysql_close提前关闭. (2)boolean mysql_create_db(数据库名

C/C++框架和库 (真的很强大) 转

http://blog.csdn.net/xiaoxiaoyeyaya/article/details/42541419 值得学习的C语言开源项目 - 1. Webbench Webbench是一个在Linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的性能,最多可以模拟3万个并发连接去测试网站的负载能力.Webbench使用C语言编写, 代码实在太简洁,源码加起来不到600行. 下载链接:http://home.tiscali