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


C++ DB_ENV::prdbt方法代码示例

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


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

示例1: load

int DbWrapper::load(std::istream *in, unsigned long *lineno)
{
	int version, ret, t_ret;
	DBTYPE dbtype;
	char *subdb = 0;
	u_int32_t read_flags, tflags;
	DBT key, data;
	db_recno_t recno, datarecno;
	DB_ENV *dbenv = environment_;
	
	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));

	if ((ret = __db_rheader(dbenv, db_, &dbtype,
				&subdb, &version, &read_flags, read_callback, in, lineno)) != 0)
		goto err;

	/* We always print with keys */
	if (!(read_flags & DB_READ_HASKEYS)) {
		db_->errx(db_, "Invalid DbXml dump: keys missing");
		ret = EINVAL;
		goto err;
	}

	if ((ret = open(NULL, dbtype, DB_CREATE|DB_EXCL)) != 0)
		goto err;

	/* Initialize the key/data pair. */
	if (dbtype == DB_RECNO || dbtype == DB_QUEUE) {
		key.size = sizeof(recno);
		key.data = &datarecno;
	} else {
		key.ulen = 1024;
		key.data = (void *)malloc(key.ulen);
	}
	data.ulen = 1024;
	data.data = (void *)malloc(data.ulen);
	if (key.data == NULL || data.data == NULL) {
		db_->err(db_, ENOMEM, NULL);
		goto err;
	}
	
	// work around gcc optimizer issue that seems to modify
	// read_flags (4.1.1 on 64-bit linux)
	tflags = read_flags;
	/* Get each key/data pair and add them to the database. */
	for (recno = 1;; ++recno) {
		if ((ret = __db_rdbt(dbenv, &key, &data,
				     tflags, read_callback, in, lineno)) != 0) {
			if (ret == EOF)
				ret = 0;
			break;
		}

		switch (ret = db_->put(db_, NULL, &key, &data, 0)) {
		case 0:
			break;
		case DB_KEYEXIST:
			db_->errx(db_, "line %d: key already exists, not loaded:", *lineno);
			dbenv->prdbt(&key, tflags & DB_READ_PRINTABLE,
				     0, &std::cerr, pr_callback, 0);
			break;
		default:
			db_->err(db_, ret, NULL);
			goto err;
		}
	}

 err:	/* Close the database. */
	if ((t_ret = close(0)) != 0 && ret == 0)
		ret = t_ret;

	/* Free allocated memory. */
	if (subdb != NULL)
		free(subdb);
	if (key.data != NULL && dbtype != DB_RECNO && dbtype != DB_QUEUE)
		free(key.data);
	if (data.data != NULL)
		free(data.data);

	return (ret);
}
开发者ID:cajus,项目名称:dbxml-debian,代码行数:82,代码来源:DbWrapper.cpp


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