当前位置: 首页>>代码示例>>C++>>正文


C++ DB::err方法代码示例

本文整理汇总了C++中DB::err方法的典型用法代码示例。如果您正苦于以下问题:C++ DB::err方法的具体用法?C++ DB::err怎么用?C++ DB::err使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB的用法示例。


在下文中一共展示了DB::err方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: db_init

/*
 * db_init --
 *	Open the database.
 */
int db_init( DB_ENV *dbenv, DB **dbpp, int dups, int pagesize)
{
    DB *dbp;
    DB_TXN *txnp;
    int ret;

    dbp = NULL;
    txnp = NULL;
    ret = 0;

    if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
        fprintf(stderr,
                "%s: db_create: %s\n", progname, db_strerror(ret));
        return (ret);
    }
    dbp->set_errfile(dbp, stderr);
    dbp->set_errpfx(dbp, progname);
    if ((ret = dbp->set_pagesize(dbp, pagesize)) != 0) {
        dbp->err(dbp, ret, "set_pagesize");
        goto err;
    }
    if (dups && (ret = dbp->set_flags(dbp, DB_DUP)) != 0) {
        dbp->err(dbp, ret, "set_flags");
        goto err;
    }

    if ((ret = dbenv->txn_begin(dbenv, NULL, &txnp, 0)) != 0)
        goto err;

    if ((ret = dbp->open(dbp, txnp, "sss.db", "primary", DB_BTREE,
                         DB_CREATE , 0664)) != 0) {
        dbp->err(dbp, ret, "%s: open", "sss.db");
        goto err;
    }
    *dbpp = dbp;

    ret = txnp->commit(txnp, 0);
    txnp = NULL;
    if (ret != 0)
        goto err;

    return (0);

err:
    if (txnp != NULL)
        (void)txnp->abort(0);
    if (dbp != NULL)
        (void)dbp->close(dbp, 0);
    return (ret);
}
开发者ID:msng4t,项目名称:network-etc,代码行数:54,代码来源:Bulk.cpp

示例2: dir_is_empty

static bool dir_is_empty(DB_TXN *txn, const struct nfs_inode *ino)
{
	int rc;
	DBC *cur = NULL;
	DB *dirent = srv.fsdb.dirent;
	DBT pkey, pval;
	struct fsdb_de_key key;
	nfsino_t rnum = 0;
	uint64_t db_dummy;

	rc = dirent->cursor(dirent, txn, &cur, 0);
	if (rc) {
		dirent->err(dirent, rc, "dirent->cursor");
		return false;
	}

	key.inum = inum_encode(ino->inum);

	memset(&pkey, 0, sizeof(pkey));
	pkey.data = &key;
	pkey.size = sizeof(key);
	pkey.flags = DB_DBT_MALLOC;

	memset(&pval, 0, sizeof(pval));
	pval.data = &db_dummy;
	pval.ulen = sizeof(db_dummy);
	pval.flags = DB_DBT_USERMEM;

	rc = cur->get(cur, &pkey, &pval, DB_SET_RANGE);
	if (rc == 0) {
		struct fsdb_de_key *rkey = pkey.data;

		rnum = inum_decode(rkey->inum);

		free(rkey);
	} else if (rc != DB_NOTFOUND)
		dirent->err(dirent, rc, "dir_is_empty cur->get");

	rc = cur->close(cur);
	if (rc) {
		dirent->err(dirent, rc, "dirent->cursor close");
		return false;
	}

	if (rnum == ino->inum)
		return false;

	return true;
}
开发者ID:jgarzik,项目名称:nfs4d,代码行数:49,代码来源:dir.c

示例3: uriindex_get

int uriindex_get (char uri[], unsigned int *DocID, unsigned int *lastmodified, char subname[]) {
        DB dbpArray;

        DB *dbp = NULL;

        DBT key, data;
        int ret;
	int forreturn = 1;
	struct uriindexFormat uriindex;

        if (!uriindex_open(&dbp,subname, DB_RDONLY)) {
		#ifdef DEBUG
			fprintf(stderr,"can't open uriindex\n");
		#endif
		return 0;
	}


        //resetter minne
        memset(&key, 0, sizeof(DBT));
        memset(&data, 0, sizeof(DBT));

	//legger inn datane i bdb strukturen
        key.data = uri;
        key.size = strlen(uri);

        if ((ret = dbp->get(dbp, NULL, &key, &data, 0)) == 0) {

		*DocID = (*(struct uriindexFormat *)data.data).DocID;
		*lastmodified = (*(struct uriindexFormat *)data.data).lastmodified;
                forreturn = 1;
        }
        else if (ret == DB_NOTFOUND) {
		#ifdef DEBUG
                	dbp->err(dbp, ret, "DBcursor->get");
			printf("search for \"%s\", len %i\n",key.data,key.size);		
		#endif
                forreturn = 0;
        }
        else {
                dbp->err(dbp, ret, "DBcursor->get");
                forreturn = 0;
        }

	uriindex_close(&dbp);

	return forreturn;

}
开发者ID:lgsonic,项目名称:enterprise-search,代码行数:49,代码来源:bbdocument.c

示例4: fprintf

/* Open a Berkeley DB database */
int
open_db(DB **dbpp, const char *progname, const char *file_name,
        DB_ENV *envp, u_int32_t extra_flags)
{
    int ret;
    u_int32_t open_flags;
    DB *dbp;

    /* Initialize the DB handle */
    ret = db_create(&dbp, envp, 0);
    if (ret != 0) {
        fprintf(stderr, "%s: %s\n", progname,
                db_strerror(ret));
        return (EXIT_FAILURE);
    }

    /* Point to the memory malloc'd by db_create() */
    *dbpp = dbp;

    if (extra_flags != 0) {
        ret = dbp->set_flags(dbp, extra_flags);
        if (ret != 0) {
            dbp->err(dbp, ret,
                     "open_db: Attempt to set extra flags failed.");
            return (EXIT_FAILURE);
        }
    }

    /* Now open the database */
    open_flags = DB_CREATE              | /* Allow database creation */
                 DB_READ_UNCOMMITTED    | /* Allow dirty reads */
                 DB_AUTO_COMMIT         | /* Allow autocommit */
                 DB_THREAD;   /* Cause the database to be free-threaded */

    ret = dbp->open(dbp,        /* Pointer to the database */
                    NULL,       /* Txn pointer */
                    file_name,  /* File name */
                    NULL,       /* Logical db name */
                    DB_BTREE,   /* Database type (using btree) */
                    open_flags, /* Open flags */
                    0);         /* File mode. Using defaults */
    if (ret != 0) {
        dbp->err(dbp, ret, "Database '%s' open failed",
                 file_name);
        return (EXIT_FAILURE);
    }
    return (EXIT_SUCCESS);
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:49,代码来源:txn_guide.c

示例5: rberkeley_db_put

/* {{{ rberkeley_db_put */
SEXP rberkeley_db_put(SEXP _dbp, SEXP _txnid, SEXP _key, SEXP _data, SEXP _flags)
{
  DB *dbp;
  DBT key, data;
  DB_TXN *txnid;
  u_int32_t flags = INTEGER(_flags)[0];
  int ret;

  memset(&key, 0, sizeof(key));
  memset(&data, 0, sizeof(data));

  key.data = (unsigned char *)RAW(_key);
  key.size = length(_key);
  data.data = (unsigned char *)RAW(_data);
  data.size = length(_data);

  dbp = R_ExternalPtrAddr(_dbp);
  if(R_ExternalPtrTag(_dbp) != RBerkeley_DB || dbp == NULL)
    error("invalid 'db' handle");

  if(!isNull(_txnid)) {
    txnid = R_ExternalPtrAddr(_txnid);
  } else txnid = NULL;

/* Store a key/data pair. */
  if ((ret = dbp->put(dbp, txnid, &key, &data, flags)) == 0) {
    return ScalarInteger(ret);
  } else {
    dbp->err(dbp, ret, "DB->put");
  }
  return R_NilValue;

}
开发者ID:rforge,项目名称:rberkeley,代码行数:34,代码来源:db.c

示例6: uriindex_delete

int uriindex_delete (char uri[], char subname[]) {

        DB *dbp = NULL;

        DBT key;
        int ret;
	int forreturn = 1;

        if (!uriindex_open(&dbp,subname, DB_CREATE)) {
		fprintf(stderr,"can't open uriindex\n");
		return 0;
	}


        //resetter minne
        memset(&key, 0, sizeof(DBT));

	//legger inn datane i bdb strukturen
        key.data = uri;
        key.size = strlen(uri);

        if ((ret = dbp->del(dbp, NULL, &key, 0)) == 0) {
		forreturn = 1;
        }
        else {
                dbp->err(dbp, ret, "DBcursor->get");
                forreturn = 0;
        }

	uriindex_close(&dbp);

	return forreturn;

}
开发者ID:oiuweirwe,项目名称:enterprise-search,代码行数:34,代码来源:bbdocument.c

示例7: berkely_registry_get

static Info* berkely_registry_get(void *self, const char* filename)
{
  DB *dbp = NULL;
  int ret;

  dbp = get_db(self);
  g_assert(dbp != NULL);

  DBT key, data;
  memset(&key, 0, sizeof(key));
  memset(&data, 0, sizeof(data));

  key.data = (void*) filename;
  key.size = strlen(filename) + 1;
  key.flags = DB_DBT_USERMEM;

  if ((ret = dbp->get(dbp, NULL, &key, &data, 0)) == 0) {
    g_debug("db: '%s' key retreived", (char*)key.data);
  } else {
    dbp->err(dbp, ret, "DB->get");
    g_warning("DB get failed");
  }

  return bab_info_unmarshall(data.data);
}
开发者ID:shanegibbs,项目名称:babirusa,代码行数:25,代码来源:dbreg.c

示例8: memset

static int
ooMindMap_keys(struct ooMindMap *self,
	       mindmap_size_t  **ids,
	       mindmap_size_t    batch_size,
	       mindmap_size_t    batch_start)
{   DBT key, data;
    DB *dbp;
    DBC *dbcp;
    int ret;

    dbp = self->_storage;

    /* initialize the key/data pair */
    memset(&key, 0, sizeof(DBT));
    memset(&data, 0, sizeof(DBT));

    /* acquire a cursor for the database */
    if ((ret = dbp->cursor(dbp, NULL, &dbcp, 0)) != 0) {
	dbp->err(dbp, ret, "DB->cursor");
	goto error;
    }

    /* TODO: batching */

    /* walk through the database and print out the key/data pairs. */
    while ((ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0)
	printf("%.*s : %.*s\n",
	       (int)key.size, (char *)key.data,
	       (int)data.size, (char *)data.data);
    if (ret != DB_NOTFOUND)
    {	dbp->err(dbp, ret, "DBcursor->get");
	goto error;
    }

    /* close everything down */
    if ((ret = dbcp->c_close(dbcp)) != 0) {
	dbp->err(dbp, ret, "DBcursor->close");
	goto error;
    }

    return oo_OK;

error:	
    (void)dbp->close(dbp, 0);
    return oo_FAIL;
}
开发者ID:M0nsteR,项目名称:OOmnik,代码行数:46,代码来源:oomindmap.c

示例9: main

int main() {
	DB *dbp;
	DB_ENV *dbenv;
	DB_TXN *xid;
	DBT key, data;
	const unsigned int INSERT_NUM = 100;
	char value[22]; /* should be log INSERT_NUM */
	int ret, i, t_ret;

        env_dir_create();
        env_open(&dbenv);

	if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
		fprintf(stderr, "db_create: %s\n", db_strerror(ret));
		exit (1);
	}

	dbenv->txn_begin(dbenv, NULL, &xid, 0);
	if ((ret = dbp->open(dbp,
					xid, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
		dbp->err(dbp, ret, "%s", DATABASE);
		goto err;
	}

	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));

	key.size = sizeof(int);
	key.data = malloc(sizeof(int));
	data.data = value;

	for( i = 0; i < INSERT_NUM; i++ ) {
		*((int*)key.data) = i;
		data.size = sizeof(char)*strlen(data.data);
		sprintf(value, "value: %u\n", i);
		dbp->put(dbp, xid, &key, &data, 0);
	}

	xid->commit(xid, 0);
	dbenv->txn_begin(dbenv, NULL, &xid, 0);
	
	for( i = 0; i < INSERT_NUM; i++ ) {
		*((int*)key.data) = i;
		dbp->get(dbp, xid, &key, &data, 0);
		printf("db: %u: key retrieved: data was %s.\n", *((int*)key.data), (char *)data.data);
	}

	xid->abort(xid);

err:    if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0)
			ret = t_ret; 


	return 0;

}
开发者ID:Zhoutall,项目名称:stasis,代码行数:56,代码来源:jbhashmany.c

示例10: sizeof

/**
 *  Retrieving a concept:
 *  if it's already cached in memory,
 *  return a reference to it,
 *  otherwise check the MindMap DB
 *  and initialize a new concept.
 */
static struct ooConcept* 
ooMindMap_get(struct ooMindMap *self, mindmap_size_t id)
{
    DB *dbp;
    DBT key, data;
    int ret;

    struct ooConcept *conc = NULL;
    char *key_buffer;
    static mindmap_size_t idsize = sizeof(mindmap_size_t);

    if (id > self->num_concepts) return NULL;

    /* check the memory cache */
    conc = (struct ooConcept*)self->concept_index[id];
    if (conc) return conc;

    dbp = self->_storage;

    /* initialize the DBTs */
    memset(&key, 0, sizeof(DBT));
    memset(&data, 0, sizeof(DBT));

    key_buffer = malloc(idsize);
    if (!key_buffer) return NULL;

    memcpy(key_buffer, &id, idsize);

    /* set the search key with the Concept id */
    key.data = key_buffer;
    key.size = idsize;

    /* get the record */
    ret = dbp->get(dbp, NULL, &key, &data, 0);
    if (ret != 0) {
        dbp->err(dbp, ret,
                 "Error searching for id: %ld", id);
        return NULL;
    }

    /* create concept */
    ret = ooConcept_new(&conc);
    if (ret != oo_OK) return NULL;

    conc->numid = id;
    conc->bytecode = (char*)data.data;
    conc->bytecode_size = (size_t)data.size;
    conc->unpack(conc);

    /* update the cache */
    self->concept_index[id] = conc;

    free(key_buffer);

    return conc;
}
开发者ID:M0nsteR,项目名称:OOmnik,代码行数:63,代码来源:oomindmap.c

示例11: uriindex_open

int uriindex_open(DB **dbpp, char subname[], u_int32_t flags) {

	DB *dbp = (*dbpp);


	char fileName[512];
	int ret;

	GetFilPathForLotFile(fileName,"urls.db",1,subname);

	#ifdef DEBUG
		printf("uriindex_open: Trying to open lotfile \"%s\"\n",fileName);
	#endif
        /********************************************************************
        * Opening nrOfFiles to stor the data in
        ********************************************************************/
                /* Create and initialize database object */
                if ((ret = db_create(&dbp, NULL, 0)) != 0) {
                        fprintf(stderr,
                            "%s: db_create: %s\n", "bbdocument", db_strerror(ret));
                        return 0;
                }

		//#define dbCashe 314572800       //300 mb
                ////setter cashe størelsen manuelt
                //if ((ret = dbp->set_cachesize(dbp, 0, dbCashe, dbCasheBlokes)) != 0) {
                //        dbp->err(dbp, ret, "set_cachesize");
                //}



                /* open the database. */
                if ((ret = dbp->open(dbp, NULL, fileName, NULL, DB_BTREE, flags, 0664)) != 0) {
                        dbp->err(dbp, ret, "%s: open", fileName);
                        //goto err1;
			//dette skjer nor collection mappen ikke er opprettet enda, typisk forde vi ikke har lagret et dokument der enda
			#ifdef DEBUG
			printf("can't dbp->open(), but db_create() was sucessful!\n");
			#endif

			dbp->close(dbp, 0);

			return 0;
                }

        /********************************************************************/

	#ifdef DEBUG
		printf("uriindex_open: finished\n");
	#endif

	(*dbpp) = dbp;

	return 1;
}
开发者ID:oiuweirwe,项目名称:enterprise-search,代码行数:55,代码来源:bbdocument.c

示例12: init_koef_db

int init_koef_db(DB **kdbp)
{
	FILE *fp;
	DB *dbp;
	DBT key, data;
	struct kdb_key	kdbkey;
	struct kdb_data	kdbdata;

	unsigned int asdu;
	unsigned int ioaf;
	float koefu, koefi;
	int ret;
	char line[LMAX];

	if ( (fp = fopen(KFILE,"r")) == NULL)
		return -1;

	if ( db_create(&dbp, NULL, 0) != 0)
		return -2;

	if ( dbp->open(dbp,NULL,NULL,NULL,DB_BTREE,DB_CREATE,0) != 0 )
		return -3;

	/* Zero out the DBTs before using them. */
	memset(&key, 0, sizeof(DBT));
	memset(&data, 0, sizeof(DBT));
	
	while(fgets(line, LMAX, fp)!=NULL){
		if (sscanf(line,"%u;%x;%f;%f\n",&asdu,&ioaf,&koefu,&koefi) < 1)
			continue;
		kdbkey.asdu = (unsigned short) asdu;
		kdbkey.ioa2 = (unsigned char)  ioaf;
		kdbdata.koef_u = koefu;
		kdbdata.koef_i = koefi;

		key.data = &kdbkey;
		key.size = sizeof(struct kdb_key);

		data.data = &kdbdata;
		data.size = sizeof(struct kdb_data);

		ret = dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE);
		if (ret != 0) {
			dbp->err(dbp, ret, "Put failed: ");
		}

	}

	fclose(fp);
	*kdbp = dbp;
	return 0;
}
开发者ID:arunanj,项目名称:mrts-ng,代码行数:52,代码来源:koef.c

示例13: del

int del (void **db, void *key, int key_len, void *value, int value_len) {
    int ret;
    DB *dbp = *db;
    DBT db_key;

    memset(&db_key, 0, sizeof(db_key));
    db_key.data = key;
    db_key.size = key_len;

    if (ret = dbp->del(dbp, NULL, key, 0)) {
        dbp->err(dbp, ret, "DB->del");
        exit(1);
    }
}
开发者ID:whitehse,项目名称:anthidium,代码行数:14,代码来源:eosimias_bdb.c

示例14: uriindex_add

int uriindex_add (char uri[], unsigned int DocID, unsigned int lastmodified, char subname[]) {
        DB dbpArray;

        DB *dbp = NULL;

        DBT key, data;
	int ret;

	struct uriindexFormat uriindex;


	#ifdef DEBUG
	printf("uriindex_add: subname %s\n",subname);
	#endif

	uriindex_open(&dbp,subname, DB_CREATE);


	//resetter minne
        memset(&key, 0, sizeof(DBT));
        memset(&data, 0, sizeof(DBT));

        //legger inn datane i bdb strukturen
        key.data = uri;
        key.size = strlen(uri);

	uriindex.DocID = DocID;
	uriindex.lastmodified = lastmodified;

        //data.data = &DocID;
        //data.size = sizeof(DocID);

	data.data = &uriindex;
	data.size = sizeof(uriindex);

        //legger til i databasen
        if  ((ret = dbp->put(dbp, NULL, &key, &data, 0)) != 0) {
                dbp->err(dbp, ret, "DB->put");
		//kan ikke returnere her for da blir den aldr lukket.
        	//return (EXIT_FAILURE);
        }
        



	uriindex_close(&dbp);



}
开发者ID:lgsonic,项目名称:enterprise-search,代码行数:50,代码来源:bbdocument.c

示例15: main

// ------------------------------------------------------------------
int main (int argc,char *argv[])
{
	cerr << "*** 開始 ***\n";

	char file_db[160];

	strcpy (file_db,argv[1]);

	cerr << "\tfile_db = " << file_db << "\n";

	DB *dbp = NULL;
	int ret;
	int t_ret;


	ret = db_create(&dbp, NULL, 0);
	if (ret != 0)
		{
	        fprintf(stderr, "db_create: %s\n", db_strerror(ret));
		}
	else
		{

//	ret = dbp->open(dbp, NULL, file_db, NULL, DB_BTREE, DB_RDONLY, 0);
	ret = dbp->open(dbp, NULL, file_db, NULL, DB_HASH, DB_RDONLY, 0);
	if (ret != 0) {
        dbp->err(dbp, ret, "%s", file_db);
	}
	else
		{
		db_cursor_read_proc (dbp,file_db);
		}

	}


    /* int DB->close(DB *db, u_int32_t flags);
     *
     * DB->close は、Berkeley DB ハンドルを閉じます。*/

	if (dbp) {
        t_ret = dbp->close(dbp, 0);
        if (t_ret != 0 && ret == 0)
		ret = t_ret;
	}

	cerr << "*** 終了 ***\n";

	exit (ret);
}
开发者ID:ekzemplaro,项目名称:data_base_language,代码行数:51,代码来源:berkeley_read.cpp


注:本文中的DB::err方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。