Exemplo n.º 1
0
/*删除索引*/
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;
}
Exemplo n.º 2
0
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();
}
Exemplo n.º 3
0
void Database::DropIndex(SQLDropIndex& st)
{
	for (auto tb = tbs_.begin(); tb != tbs_.end(); tb++)
	{
		for (auto idx = tb->get_ids().begin(); idx != tb->get_ids().end(); idx++)
		{
			if (idx->get_name() == st.get_index_name())
			{
				tb->get_ids().erase(idx);
				return ;
			}
		}
	}
}