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


C++ Db类代码示例

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


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

示例1: Db

Db * BDBBackend::get_db (const string & bucket)
{
    Db * db = dbs[bucket];
    if (!db)
    {
        u_int32_t db_flags = DB_AUTO_COMMIT; // allow auto-commit

        db = new Db (this->db_env, 0);
        try
        {
            db->open (NULL,                 // Txn pointer
                      bucket.c_str (),   // file name
                      NULL,                 // logical db name
                      DB_BTREE,             // database type
                      db_flags,             // open flags
                      0);                   // file mode, defaults
            dbs[bucket] = db;
        }
        catch (DbException & e)
        {
            delete db;
            T_ERROR("get_db: exception=%s", e.what ());
            ThrudocException de;
            de.what = "BDBBackend error";
            throw de;
        }
    }
    return db;
}
开发者ID:jakesays,项目名称:thrudb,代码行数:29,代码来源:BDBBackend.cpp

示例2: throw

Table Database::getTable(const std::string &tableName) throw (DbException)
{
	uint32_t dbFlags = DB_CREATE | DB_AUTO_COMMIT;
	Db *db = new Db(&m_env, 0);
	db->open(NULL, tableName.c_str(), NULL, DB_BTREE, dbFlags, 0);
	return Table(db);
}
开发者ID:wangping0214,项目名称:catman,代码行数:7,代码来源:Database.cpp

示例3: operator

void process_results_callable::operator ()(Nids *nids, const char *db_filename)
{
    Db db;
    if (db_filename && db_filename[0])
        db.open(db_filename);

    while(true) {
        nids->process_result_sem.wait();

        if (nids->threads_exit)
            break;

        if (db.is_opened())
            nids->process_result(&db);
        else
            nids->process_result(NULL);
    }

    if (db_filename && db_filename[0])
        db.close();

    nids->threads_finished_sem.post();
    BOOST_LOG_TRIVIAL(trace) << "process_result thread finished successfully" << endl;
    cout << "process result thread finished" << endl;
}
开发者ID:xeppaka,项目名称:ganids,代码行数:25,代码来源:nids.cpp

示例4: memset

HeaderGroup* BulkHeaderGroup::getGroup(NewsGroup* ng, QString& articleIndex)
{
    HeaderGroup *hg = 0;

    int ret;
    Dbt groupkey;
    Dbt groupdata;
    memset(&groupkey, 0, sizeof(groupkey));
    memset(&groupdata, 0, sizeof(groupdata));
    groupdata.set_flags(DB_DBT_MALLOC);

    QByteArray ba = articleIndex.toLocal8Bit();
    const char *k= ba.constData();
    groupkey.set_data((void*)k);
    groupkey.set_size(articleIndex.length());

    Db* groupsDb = ng->getGroupingDb();
    ret=groupsDb->get(NULL, &groupkey, &groupdata, 0);
    if (ret != 0) //key not found
    {
        qDebug() << "Failed to find group with key " << articleIndex;
    }
    else
    {
        qDebug() << "Found group with key " << articleIndex;

        hg=new HeaderGroup(articleIndex.length(), (char*)k, (char*)groupdata.get_data());
        void* ptr = groupdata.get_data();
        Q_FREE(ptr);
    }

    return hg;
}
开发者ID:quban2,项目名称:quban,代码行数:33,代码来源:bulkHeaderGroup.cpp

示例5: t6

void t6(int except_flag)
{
	cout << "  Running test 6:\n";

	/* From user [#2939] */
	int err;

	DbEnv* penv = new DbEnv(DB_CXX_NO_EXCEPTIONS);
	penv->set_cachesize(0, 32 * 1024, 0);
	penv->open(CONSTRUCT01_DBDIR, DB_CREATE | DB_PRIVATE | DB_INIT_MPOOL, 0);

	//LEAK: remove this block and leak disappears
	Db* pdb = new Db(penv,0);
	if ((err = pdb->close(0)) != 0) {
		fprintf(stderr, "Error closing Db: %s\n", db_strerror(err));
	}
	delete pdb;
	//LEAK: remove this block and leak disappears

	if ((err = penv->close(0)) != 0) {
		fprintf(stderr, "Error closing DbEnv: %s\n", db_strerror(err));
	}
	delete penv;

	cout << "  finished.\n";
}
开发者ID:disenone,项目名称:wpython-2.7.11,代码行数:26,代码来源:TestConstruct01.cpp

示例6: main

int main(int argc, char *argv[])
{
	try {
		Db *db = new Db(NULL, 0);
		db->open(NULL, "my.db", NULL, DB_BTREE, DB_CREATE, 0);

		// populate our massive database.
		// all our strings include null for convenience.
		// Note we have to cast for idiomatic
		// usage, since newer gcc requires it.
		set<string> hash;
		rand_init();
		FILE*file=fopen("mydb","w");
		for(int i=0;i<num_record;i++){
			cout<<i<<endl;
			string str_key=rand_str(5,15);
			while(hash.count(str_key)!=0)
				str_key=rand_str(5,15);
			hash.insert(str_key);
			Dbt *keydbt = new Dbt((char *)str_key.c_str(), str_key.size()+1);
			string str_data=rand_str(150,250);
			Dbt *datadbt = new Dbt((char *)str_data.c_str(), str_data.size()+1);
			db->put(NULL, keydbt, datadbt, 0);
			fprintf(file,"%d\n%s\n%s\n",i,str_key.c_str(),str_data.c_str());
		}
		fclose(file);
		db->close(0);
	
	}catch (DbException &dbe) {
		cerr << "Db Exception: " << dbe.what();
	}

	return 0;
}
开发者ID:fmars,项目名称:NoSQLCompare,代码行数:34,代码来源:TestSimpleAccess_insert.cpp

示例7: DB_ERROR

//static
int Db::_append_recno_intercept(DB *db, DBT *data, db_recno_t recno)
{
	int err;

	if (db == 0) {
		DB_ERROR("Db::append_recno_callback", EINVAL, ON_ERROR_UNKNOWN);
		return (EINVAL);
	}
	Db *cxxdb = (Db *)db->cj_internal;
	if (cxxdb == 0) {
		DB_ERROR("Db::append_recno_callback", EINVAL, ON_ERROR_UNKNOWN);
		return (EINVAL);
	}
	if (cxxdb->append_recno_callback_ == 0) {
		DB_ERROR("Db::append_recno_callback", EINVAL, cxxdb->error_policy());
		return (EINVAL);
	}

	// making these copies is slow but portable.
	// Another alternative is to cast the DBT* manufactured
	// by the C layer to a Dbt*.  It 'should be' safe since
	// Dbt is a thin shell over DBT, adding no extra data,
	// but is nonportable, and could lead to errors if anything
	// were added to the Dbt class.
	//
	Dbt cxxdbt;
	memcpy((DBT *)&cxxdbt, data, sizeof(DBT));
	err = (*cxxdb->append_recno_callback_)(cxxdb, &cxxdbt, recno);
	memcpy(data, (DBT *)&cxxdbt, sizeof(DBT));
	return (err);
}
开发者ID:NickeyWoo,项目名称:mysql-3.23.49,代码行数:32,代码来源:cxx_table.cpp

示例8: __db_close_int

extern "C" int
__db_close_int(long id, u_int32_t flags)
{
	Db *dbp;
	int ret;
	ct_entry *ctp;

	ret = 0;
	ctp = get_tableent(id);
	if (ctp == NULL)
		return (DB_NOSERVER_ID);
	DB_ASSERT(ctp->ct_type == CT_DB);
	if (__dbsrv_verbose && ctp->ct_refcount != 1)
		printf("Deref'ing dbp id %ld, refcount %d\n",
		    id, ctp->ct_refcount);
	if (--ctp->ct_refcount != 0)
		return (ret);
	dbp = ctp->ct_dbp;
	if (__dbsrv_verbose)
		printf("Closing dbp id %ld\n", id);

	ret = dbp->close(flags);
	__dbdel_ctp(ctp);
	return (ret);
}
开发者ID:dmeister,项目名称:kbdb,代码行数:25,代码来源:db_server_cxxutil.cpp

示例9: strlen

int DiskBDB::Truncate ( const Vdt *dzname )
{
    int ret = -1;
    int numPartition = 0;
    DbTxn* txn = NULL;
    Db *DbHandle;
    numPartition = m_dzManager->GetNumPartition( *dzname );
    string s_dzname = "";
    uint num_deleted = 0;
    const char **pathArray;
    m_DiskEnv->get_data_dirs(&pathArray);
    string s_datadir_init = pathArray[0];
    string s_datadir, s_pathFile;

    TCUtility::fixDataDirectoryPath( s_datadir_init, s_datadir );

    for( int i = 0; i < numPartition; i++ )
    {
        //txn = NULL;
        //m_DiskEnv->txn_begin(NULL, &txn, 0);
        s_pathFile.clear();
        s_dzname.clear();
        //s_dzname = "";
        m_dzManager->AppendPartitionID(*dzname, i, s_dzname);
        s_dzname += TC_TRUCATE_DZONE_MASK;
        s_pathFile =  s_datadir + s_dzname;
        //ret = m_dzManager->GetHandleForPartition( s_dzname.c_str(), strlen(s_dzname.c_str()), DbHandle );
        //ret = m_dzManager->OpenHandleNoEnv( s_dzname.c_str(), strlen(s_dzname.c_str()), DbHandle );
        ret = m_dzManager->OpenHandleNoEnv( s_pathFile.c_str(), strlen(s_pathFile.c_str())+1, DbHandle );
        //handle ret!=0
        //blablabla...

        try
        {
            ret = DbHandle->truncate(NULL, &num_deleted, 0);
            //ret = DbHandle->truncate( txn, &num_deleted, 0 );
            //handle ret!=0
            //blablabla...
            //txn->commit(0);
        }
        catch(DbException ex)
        {
            ret = ex.get_errno();
            cout << ex.what();
            cout << ex.get_errno();
            cout<<"Error. DiskBDB::Truncate-> Exception encountered while truncating DiskBDB for DZName: " << s_dzname << endl;
            //txn->abort();
        }

        DbHandle->close(0);
    }

    if(ret!=0)
    {
        cout<<"The Handle was not retrieved from datazone manager"<<endl;
        return ret;
    }

    return ret;
}
开发者ID:mbsky,项目名称:tcache,代码行数:60,代码来源:DiskBDB.cpp

示例10: openDb

// Open a Berkeley DB database
int
openDb(Db **dbpp, const char *progname, const char *fileName,
  DbEnv *envp, u_int32_t extraFlags)
{
    int ret;
    u_int32_t openFlags;

    try {
        Db *dbp = new Db(envp, 0);

        // Point to the new'd Db
        *dbpp = dbp;

        if (extraFlags != 0)
            ret = dbp->set_flags(extraFlags);

        // Now open the database */
        openFlags = DB_CREATE        | // Allow database creation
                    DB_THREAD        |
                    DB_AUTO_COMMIT;    // Allow autocommit

        dbp->open(NULL,       // Txn pointer
                  fileName,   // File name
                  NULL,       // Logical db name
                  DB_BTREE,   // Database type (using btree)
                  openFlags,  // Open flags
                  0);         // File mode. Using defaults
    } catch (DbException &e) {
        std::cerr << progname << ": openDb: db open failed:" << std::endl;
        std::cerr << e.what() << std::endl;
        return (EXIT_FAILURE);
    }

    return (EXIT_SUCCESS);
}
开发者ID:AdeebNqo,项目名称:poedit,代码行数:36,代码来源:TxnGuideInMemory.cpp

示例11: testDb

void testDb(Db dbEngLab, Table *ptblTeacher)
{
	DB_RET		Ret;

	Ret = dbEngLab.open("EngLab", "D:\\Dropbox\\develop");
	Ret = dbEngLab.addTable(ptblTeacher);
	Ret = dbEngLab.save();
	Ret = dbEngLab.commit();
}
开发者ID:albert43,项目名称:c_database_AlDb,代码行数:9,代码来源:main.cpp

示例12: assert

int Account::DoUserLogin(Login& login,Db& db,UserRecord& userRecord){
	char sql[256];
	const int maxArray = 256;
	if ( login.phone_len > maxArray )
	{
		assert(false);
		return kError;
	}

	string phone = "";
	phone.assign(login.phone,login.phone_len);

	sprintf_s(sql,"select * from playerInfo where  phone = \"%s\"",phone.c_str());
	db.ReadDb(sql);
	if (db.nRow > 0)
	{
		time_t now_time;
		now_time = time(NULL);
		userRecord.login_time = (uint32_t)now_time;
		
		string str_player_id = db.pazResult[db.nCol];
		userRecord.user_id = atoi(str_player_id.c_str());

		string nick = db.pazResult[db.nCol+1];
		userRecord.nick.len = strlen(nick.c_str());
		memcpy(userRecord.nick.name,nick.c_str(),userRecord.nick.len);
		 
		string str_age = db.pazResult[db.nCol+2];
		userRecord.age = atoi(str_age.c_str());

		string str_forbid_login_time = db.pazResult[db.nCol + 3];
		userRecord.forbid_login_time = atoi(str_forbid_login_time.c_str());

		string str_phone = db.pazResult[db.nCol + 5];
		memcpy(userRecord.phone,str_phone.c_str(),strlen(str_phone.c_str()));

		string str_address_1 = db.pazResult[db.nCol + 6];
		userRecord.address1_len = str_address_1.length();
		memcpy(userRecord.address1,str_address_1.c_str(),userRecord.address1_len);

		string str_address_2 = db.pazResult[db.nCol + 7];
		userRecord.address2_len = str_address_2.length();
		memcpy(userRecord.address2,str_address_2.c_str(),userRecord.address2_len);

		string str_address_3 = db.pazResult[db.nCol + 8];
		userRecord.address3_len = str_address_3.length();
		memcpy(userRecord.address3,str_address_3.c_str(),userRecord.address3_len);

		db.freeTableData();
	}else{
		return kUserOrPasswdError;
	}
	
	return kSucess;
}
开发者ID:adocode,项目名称:GameServer,代码行数:55,代码来源:account.cpp

示例13: test_new_open_delete

void test_new_open_delete() {
    system("rm -rf " DIR);
    toku_os_mkdir(DIR, 0777);
    DbEnv env(0);
    { int r = env.set_redzone(0); assert(r==0); }
    { int r = env.open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777); assert(r == 0); }
    Db *db = new Db(&env, 0); assert(db != 0);
    { int r = db->open(NULL, FNAME, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0); }
    { int r = db->close(0); assert(r == 0); }
    delete db;
}
开发者ID:Alienfeel,项目名称:ft-index,代码行数:11,代码来源:test_db_delete.cpp

示例14: key

int DiskBDB::Get (const Vdt& dzname, const Vdt& Key, Vdt *Value,stats *stats_update)
{
    Db *DbHandle;
    Dbt dbt_value;
    int ret=0;
    //ret=m_dzManager->GetHandleForPartition("B0",2,DbHandle);
    ret=m_dzManager->Get(dzname,Key,DbHandle);
    if(ret!=0)
    {
        cout<<"Datazone handle not retrieved from datazone manager"<<endl;
        return ret;
    }

    Dbt key(Key.get_data(),Key.get_size());
    dbt_value.set_data((*Value).get_data());
    dbt_value.set_size((*Value).get_size());
    dbt_value.set_ulen((*Value).get_size() );
    dbt_value.set_flags( DB_DBT_USERMEM );

    bool keepTrying=true;
    int numTries=0;
    while(keepTrying && numTries < m_maxDeadlockRetries)
    {
        numTries++;
        try {
            ret=DbHandle->get(NULL,&key,&dbt_value,0);
            keepTrying=false;
            if( ret == 0 )
                Value->set_size( dbt_value.get_size() );
        }
        catch(DbException &e) {
            if(numTries==1)
                printf("DiskBDB Get::%s\n",e.what());

            ret=e.get_errno();

            if(ret==DB_LOCK_DEADLOCK)
            {
                if(stats_update)
                    stats_update->NumDeadlocks++;
            }
            else
                keepTrying=false;

            if( ret==DB_BUFFER_SMALL )
                (*Value).set_size(dbt_value.get_size());
        } catch(exception &e) {
            cout << e.what() << endl;
            return (-1);
        }
    }
    return ret;
}
开发者ID:mbsky,项目名称:tcache,代码行数:53,代码来源:DiskBDB.cpp

示例15: Db

/* Initialize the database. */
void BulkExample::initDb(int dups, int sflag, int pagesize) {

	DbTxn *txnp;
	int ret;

	txnp = NULL;
	ret = 0;

	dbp = new Db(dbenv, 0);

	dbp->set_error_stream(&cerr);
	dbp->set_errpfx(progname);

	try{
		if ((ret = dbp->set_bt_compare(compare_int)) != 0)
			throwException(dbenv, NULL, ret, "DB->set_bt_compare");

		if ((ret = dbp->set_pagesize(pagesize)) != 0)
			throwException(dbenv, NULL, ret, "DB->set_pagesize");

		if (dups && (ret = dbp->set_flags(DB_DUP)) != 0)
			throwException(dbenv, NULL, ret, "DB->set_flags");

		if ((ret = dbenv->txn_begin(NULL, &txnp, 0)) != 0)
			throwException(dbenv, NULL, ret, "DB_ENV->txn_begin");

		if ((ret = dbp->open(txnp, DATABASE, "primary", DB_BTREE,
		    DB_CREATE, 0664)) != 0)
			throwException(dbenv, txnp, ret, "DB->open");

		if (sflag) {
			sdbp = new Db(dbenv, 0);

			if ((ret = sdbp->set_flags(DB_DUPSORT)) != 0)
				throwException(dbenv, txnp,
				    ret, "DB->set_flags");

			if ((ret = sdbp->open(txnp, DATABASE, "secondary",
			    DB_BTREE, DB_CREATE, 0664)) != 0)
				throwException(dbenv, txnp, ret, "DB->open");

			if ((ret =  dbp->associate(
			    txnp, sdbp, get_first_str, 0)) != 0)
				throwException(dbenv, txnp,
				    ret, "DB->associate");
		}

		ret = txnp->commit(0);
		txnp = NULL;
		if (ret != 0)
			throwException(dbenv, NULL, ret, "DB_TXN->commit");
	} catch(DbException &dbe) {
		cerr << "initDb " << dbe.what() << endl;
		if (txnp != NULL)
			(void)txnp->abort();
		throw dbe;
	}
}
开发者ID:crossbuild,项目名称:db,代码行数:59,代码来源:BulkExample.cpp


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