/*删除索引*/ void API::DropIndex(SQLDropIndex& sql_statement) { if (current_database_.length() == 0)/*判断当前数据库是否选定*/ { throw NoDatabaseSelectedException(); } Database *db = catalog_manager_->GetDB(current_database_); if (db == NULL)/*判断当前数据库是否存在*/ { throw DatabaseNotExistException(); } if (!db->CheckIfIndexExists(sql_statement.get_index_name()))/*【catalog manager】判断index是否存在*/ { throw IndexNotExistException(); } string file_name(path_ + current_database_ + "/" + sql_statement.get_index_name() + ".index");/*【file system】获取文件地址*/ if (!boost::filesystem::exists(file_name))/*【file system】利用boost库判断当前文件是否存在*/ { cout << "索引文件不存在" << endl; return; } boost::filesystem::remove(file_name);/*【file system】利用boost库删除文件地址对应文件*/ cout << "索引文件已删除。" << endl; db->DropIndex(sql_statement);/*【catalog manager】目录结构中删除索引*/ cout << "目录文件已写入。" << endl; catalog_manager_->WriteArchiveFile();/*【catalog manager】在catalog中写文档*/ //cout << "删除索引。" << endl; }
void API::CreateIndex(SQLCreateIndex& statement) { cout << "Creating Index: " << statement.get_index_name() << endl; if (current_db_.length() == 0) throw NoDatabaseSelectedException(); Database *db = catalog_m_->GetDB(current_db_); if (db->GetTable(statement.get_tb_name()) == NULL) throw TableNotExistException(); if (db->CheckIfIndexExists(statement.get_index_name()) ) throw IndexAlreadyExistsException(); IndexManager *im = new IndexManager(catalog_m_, buffer_m_, current_db_); im->CreateIndex(statement); delete im; }
void API::DropIndex(SQLDropIndex& statement) { if (current_db_.length() == 0) throw NoDatabaseSelectedException(); Database *db = catalog_m_->GetDB(current_db_); if (db == NULL) throw DatabaseNotExistException(); if (!db->CheckIfIndexExists(statement.get_index_name())) throw IndexNotExistException(); string file_name(path_ + current_db_ + "/" + statement.get_index_name() + ".index"); if (!boost::filesystem::exists(file_name)) { cout << "Index file doesn't exist!" << endl; return; } boost::filesystem::remove(file_name); cout << "Index file removed!" << endl; db->DropIndex(statement); cout << "Catalog written!" << endl; catalog_m_->WriteArchiveFile(); }