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; }
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); }
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; }
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; }
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"; }
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; }
//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); }
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); }
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; }
// 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); }
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(); }
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; }
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; }
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; }
/* 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; } }
Db* Db::open(const std::string &path){ std::string dir = path; if(path[path.size() - 1] != '/'){ dir = path + "/"; } Db *db = new Db(); db->_path = dir; if(db->init() == -1){ delete db; return NULL; } return db; }
void CDBEnv::CloseDb(const string& strFile) { { LOCK(cs_db); if (mapDb[strFile] != NULL) { Db* pdb = mapDb[strFile]; pdb->close(0); delete pdb; mapDb[strFile] = NULL; } } }
void BerkeleyEnvironment::CloseDb(const std::string& strFile) { { LOCK(cs_db); if (mapDb[strFile] != nullptr) { // Close the database handle Db* pdb = mapDb[strFile]; pdb->close(0); delete pdb; mapDb[strFile] = nullptr; } } }
void Controller::runTWI() { chrono::milliseconds sleepDuration(2000); //tmp this_thread::sleep_for(sleepDuration); TWI twi = TWI(); LngLat currGoal = LngLat(0., 0.); Db db = Db::getInstance(); while(!endThreads) { this->lngLatCurrent = db.getFakeTWI(); // todo: get current positon from ATmega if(sizeof(this->map)>0 && !this->mapLoading) // sprawdź czy pozycja jest granicach mapy this->positionInBounds = this->map->inBounds(this->lngLatCurrent); if(this->goalPath.size() > 0) { // ścieżka wyznaczona if(this->sentPoint == 0) { // nowa ścieżka this->twiStatus = twi.writeFirstGoal(this->goalPath[0].toLngLat(this->map)); if(this->twiStatus < -1) { // twi ok currGoal = this->goalPath[1].toLngLat(this->map); this->twiStatus = twi.writeNextGoal(currGoal); if(this->twiStatus > -1) { // twi ok this->sentPoint=1; } else { // twi error // elog << "Problem z komunikacją TWI: " << this->twiStatus; } } else { // twi error // elog << "Problem z komunikacją TWI: " << this->twiStatus; } } else { // kontynuuj wysyłanie trajektorii LngLat tmp = twi.getCurrentGoal(); // dlog << "current goal from robot: " << tmp; // dlog << "current set goal: " << currGoal; if(tmp == currGoal) { // robot podąża do 'następnego' celu // wyślij nowy 'następny' cel this->sentPoint++; if(this->sentPoint < this->goalPath.size()) { // pozostały punkty trajektorii do wysłania currGoal = this->goalPath[this->sentPoint].toLngLat(this->map); this->twiStatus = twi.writeNextGoal(currGoal); if(this->twiStatus <= -1) { // twi error // elog << "Problem z komunikacją TWI: " << this->twiStatus; } } else { // wysłano ostatni punkt } } } } // opóźnij wątek chrono::milliseconds sleepDuration(2000); this_thread::sleep_for(sleepDuration); } dlog << "koniec threadTWI"; }
void CloseDb(const string& strFile) { { LOCK(cs_db); if (mapDb[strFile] != NULL) { // Close the database handle Db* pdb = mapDb[strFile]; pdb->close(0); delete pdb; mapDb[strFile] = NULL; } } }
void CDBEnv::CloseDb(const string& strFile) { { LOCK(cs_db); if (mapDb[strFile] != NULL) { // Close the database handle Закрыть дескриптор базы данных Db* pdb = mapDb[strFile]; pdb->close(0); delete pdb; mapDb[strFile] = NULL; } } }
int DiskBDB::Put (const Vdt& dzname, const Vdt& Key, const Vdt& Value, stats *stats_update) { Db *DbHandle; int ret=0; ret=m_dzManager->Get(dzname,Key,DbHandle); if(ret!=0) { printf("Datazone handle not retrieved from datazone manager\n"); return ret; } Dbt key(Key.get_data(),Key.get_size()); Dbt value(Value.get_data(),Value.get_size()); key.set_ulen(Key.get_size()); key.set_flags( DB_DBT_USERMEM ); value.set_ulen(Value.get_size() ); value.set_flags( DB_DBT_USERMEM ); bool keepTrying=true; int numTries=0; while(keepTrying && numTries < m_maxDeadlockRetries) { numTries++; try { ret=DbHandle->put(NULL,&key,&value,0); keepTrying=false; } catch(DbException &e) { //if(numTries==1) //printf("DiskBDB Put::%s\n",e.what()); ret=e.get_errno(); if(ret==DB_LOCK_DEADLOCK) { if(stats_update) stats_update->NumDeadlocks++; } else keepTrying=false; } catch(exception &e) { printf("%s\n",e.what()); return (-1); } } return ret; }
int main(int argc, char *argv[]) { try { Db *db = new Db(NULL, 0); db->open(NULL, "my.db", NULL, DB_BTREE, DB_CREATE, 0644); // populate our massive database. // all our strings include null for convenience. // Note we have to cast for idiomatic // usage, since newer gcc requires it. Dbt *keydbt = new Dbt((char *)"key", 4); Dbt *datadbt = new Dbt((char *)"data", 5); db->put(NULL, keydbt, datadbt, 0); // Now, retrieve. We could use keydbt over again, // but that wouldn't be typical in an application. Dbt *goodkeydbt = new Dbt((char *)"key", 4); Dbt *badkeydbt = new Dbt((char *)"badkey", 7); Dbt *resultdbt = new Dbt(); resultdbt->set_flags(DB_DBT_MALLOC); int ret; if ((ret = db->get(NULL, goodkeydbt, resultdbt, 0)) != 0) { cout << "get: " << DbEnv::strerror(ret) << "\n"; } else { char *result = (char *)resultdbt->get_data(); cout << "got data: " << result << "\n"; } if ((ret = db->get(NULL, badkeydbt, resultdbt, 0)) != 0) { // We expect this... cout << "get using bad key: " << DbEnv::strerror(ret) << "\n"; } else { char *result = (char *)resultdbt->get_data(); cout << "*** got data using bad key!!: " << result << "\n"; } cout << "finished test\n"; } catch (DbException &dbe) { cerr << "Db Exception: " << dbe.what(); } return 0; }
//static void Db::_feedback_intercept(DB *db, int opcode, int pct) { if (db == 0) { DB_ERROR("Db::feedback_callback", EINVAL, ON_ERROR_UNKNOWN); return; } Db *cxxdb = (Db *)db->cj_internal; if (cxxdb == 0) { DB_ERROR("Db::feedback_callback", EINVAL, ON_ERROR_UNKNOWN); return; } if (cxxdb->feedback_callback_ == 0) { DB_ERROR("Db::feedback_callback", EINVAL, cxxdb->error_policy()); return; } (*cxxdb->feedback_callback_)(cxxdb, opcode, pct); }
Berkley(const string& dbname) :_env(0), _dbname(dbname) { _env.set_error_stream(&std::cerr); _env.open("/tmp/", DB_CREATE|DB_INIT_MPOOL,0); _db = new Db(&_env, 0); _db->open(nullptr, _dbname.c_str(), nullptr, DB_BTREE, DB_CREATE|DB_TRUNCATE, 0); };
int Account::DoUserRegister(Register ®ister_,Db &db,int playerId){ char sql[256]; time_t now_time; now_time = time(NULL); int forbid_login_time = 0; char nick[48] = "\0"; //nick.assign(register_.nick.name,register_.nick.len); int a = register_.nick.len; memcpy(nick,register_.nick.name,register_.nick.len); char phone[12] = "\0"; //phone.assign(register_.phone,register_.phone_len); memcpy(phone,register_.phone,register_.phone_len); char address_1[512] = "\0"; memcpy(address_1,register_.address1,register_.address1_len); char address_2[512] = "\0"; memcpy(address_2,register_.address2,register_.address2_len); char address_3[512] = "\0"; memcpy(address_3,register_.address3,register_.address3_len); sprintf_s(sql, "insert into playerInfo values(%d, \'%s\', %d, %d, %d, \'%s\', \'%s\', \'%s\', \'%s\');", playerId,nick,register_.age,int(now_time),forbid_login_time,phone,address_1,address_2,address_3); string sql_find_nick = "select player_id from playerInfo where nick = \'" + (string)nick + "\'"; char sql_updatePlayerId[256]; sprintf_s(sql_updatePlayerId,"update playerMaxId set player_max_id = %d",playerId); db.ReadDb(sql_find_nick); if (db.nRow == 1) { db.freeTableData(); return kSameNick; }else{ db.freeTableData(); db.WriteDb(sql); db.WriteDb(sql_updatePlayerId); } return kSucess; }
int DbMigrat::Migrate(Db & db) { cout << "\n-----------------------------------------------------------"; cout << "\nUSE THE DB2 API:" << endl; cout << " sqlemgdb -- MIGRATE DATABASE" << endl; cout << "TO MIGRATE A DATABASE TO CURRENT FORMATS." << endl; cout << "\n Migrate the \"" << db.getAlias() << "\" database." << endl; // migrate the database sqlemgdb(db.getAlias(), db.getUser(), db.getPswd(), &sqlca); if (sqlca.sqlcode != SQLE_RC_MIG_OK) { DB2_API_CHECK("Database -- Migrate"); } return 0; } //DbMigrat::Migrate
int main(int argc, const char* argv[]) { if (argc !=3) { cout << "usage: "<< argv[0] << " <filename> <db filename>" << endl; return 1; } const char* kDatabaseName = argv[2]; const char* filename = argv[1]; DbEnv env(0); Db* pdb; try { env.set_error_stream(&cerr); env.open("./", DB_CREATE | DB_INIT_MPOOL, 0); pdb = new Db(&env, 0); pdb->set_flags(DB_DUP); // Create (or clear its content if it exists) the database pdb->open(NULL, kDatabaseName, NULL, DB_BTREE, DB_CREATE | DB_TRUNCATE, 0); readfile(pdb, filename); readfile(pdb, "tables/jp.txt"); // Clean up if (pdb != NULL) { pdb->close(0); delete pdb; } env.close(0); } catch (DbException& e) { cerr << "DbException: " << e.what() << endl; return -1; } catch (std::exception& e) { cerr << e.what() << endl; return -1; } return 0; }
/* ** This routine is called by the parser to process a DETACH statement: ** ** DETACH DATABASE dbname ** ** The pDbname argument is the name of the database in the DETACH statement. */ void sqliteDetach(Parse *pParse, Token *pDbname){ int i; sqlite *db; Vdbe *v; Db *pDb; v = sqliteGetVdbe(pParse); sqliteVdbeAddOp(v, OP_Halt, 0, 0); if( pParse->explain ) return; db = pParse->db; for(i=0; i<db->nDb; i++){ pDb = &db->aDb[i]; if( pDb->pBt==0 || pDb->zName==0 ) continue; if( strlen(pDb->zName)!=pDbname->n ) continue; if( sqliteStrNICmp(pDb->zName, pDbname->z, pDbname->n)==0 ) break; } if( i>=db->nDb ){ sqliteErrorMsg(pParse, "no such database: %T", pDbname); return; } if( i<2 ){ sqliteErrorMsg(pParse, "cannot detach database %T", pDbname); return; } #ifndef SQLITE_OMIT_AUTHORIZATION if( sqliteAuthCheck(pParse,SQLITE_DETACH,db->aDb[i].zName,0,0)!=SQLITE_OK ){ return; } #endif /* SQLITE_OMIT_AUTHORIZATION */ sqliteBtreeClose(pDb->pBt); pDb->pBt = 0; sqliteFree(pDb->zName); sqliteResetInternalSchema(db, i); if( pDb->pAux && pDb->xFreeAux ) pDb->xFreeAux(pDb->pAux); db->nDb--; if( i<db->nDb ){ db->aDb[i] = db->aDb[db->nDb]; memset(&db->aDb[db->nDb], 0, sizeof(db->aDb[0])); sqliteResetInternalSchema(db, i); } }
int DiskBDB::Delete (const Vdt&dzname, const Vdt&Key,stats *stats_update) { Db *DbHandle; int ret=0; ret=m_dzManager->Get(dzname,Key,DbHandle); if(ret!=0) { cout<<"The Handle was not retrieved from datazone manager"<<endl; return ret; } Dbt key(Key.get_data(),Key.get_size()); bool keepTrying=true; int numTries=0; while(keepTrying && numTries < m_maxDeadlockRetries) { numTries++; try { ret=DbHandle->del(NULL,&key,0); keepTrying=false; } catch(DbException &e) { if(numTries==1) printf("DiskBDB Delete::%s\n",e.what()); ret=e.get_errno(); if(ret==DB_LOCK_DEADLOCK) { if(stats_update) stats_update->NumDeadlocks++; } else keepTrying=false; } catch(exception &e) { cout << e.what() << endl; return (-1); } } return ret; }