Esempio n. 1
0
/*删除数据表*/
void API::DropTable(SQLDropTable& sql_statement)
{
	cout << "Droping table: " << sql_statement.get_table_name() << endl;
	if (current_database_.length() == 0)/*判断当前数据库是否选定*/
	{
		throw NoDatabaseSelectedException();
	}

	Database *db = catalog_manager_->GetDB(current_database_);
	if (db == NULL)/*判断该当前数据库是否存在*/
	{
		throw DatabaseNotExistException();
	}

	Table *tb = db->GetTable(sql_statement.get_table_name());
	if (tb == NULL)/*判断该数据库是否存在数据表*/
	{
		throw TableNotExistException();
	}
	string file_name(path_ + current_database_ + "/" + sql_statement.get_table_name() + ".records");/*获取该数据表的文件地址*/

	if (!boost::filesystem::exists(file_name))/*【file system】利用boost库判断该文件是否存在*/
	{
		cout << sql_statement.get_table_name() +" 数据表文件不存在。" << endl;
	}
	else
	{
		boost::filesystem::remove(file_name);/*【file system】利用boost库删除该文件*/
		cout << sql_statement.get_table_name() + "数据表文件已删除。" << endl;
	}

	cout << "删除数据表下索引文件。" << endl;
	for (unsigned int i = 0; i < tb->GetIndexNum(); i++)
	{
		string file_name(path_ + current_database_ + "/" + tb->GetIndex(i)->get_name() + ".index");/*获取该数据表的文件地址*/
		if (!boost::filesystem::exists(file_name))/*【file system】利用boost库判断该文件是否存在*/
		{
			cout << "索引文件不存在。" << endl;
		}
		else
		{
			boost::filesystem::remove(file_name);
			cout << "索引文件已删除" << endl;
		}
	}

	db->DropTable(sql_statement);/*【catalog manager】在目录中删除该数据表*/
	cout << "目录文件已写入。" << endl;
	catalog_manager_->WriteArchiveFile();/*【catalog manager】在catalog中写文档*/
	//cout << "删除数据表。" << endl;
}
Esempio n. 2
0
void API::DropTable(SQLDropTable& statement)
{
	cout << "Droping table: " << statement.get_tb_name() << endl;
	if (current_db_.length() == 0) throw NoDatabaseSelectedException();

	Database *db = catalog_m_->GetDB(current_db_);
	if (db == NULL) throw DatabaseNotExistException();

	Table *tb = db->GetTable(statement.get_tb_name());
	if (tb == NULL) throw TableNotExistException();
	
	string file_name(path_ + current_db_ + "/" + statement.get_tb_name() + ".records");

	if (!boost::filesystem::exists(file_name)) cout << "Table file doesn't exists!" << endl;
	else
	{
		boost::filesystem::remove(file_name);
		cout << "Table file deleted!" << endl;
	}

	cout << "Removing Index files!" << endl;
	for (unsigned int i = 0; i < tb->GetIndexNum(); i++)
	{
		string file_name(path_ + current_db_ + "/" + tb->GetIndex(i)->get_name() + ".index");
		if (!boost::filesystem::exists(file_name)) cout << "Index file doesn't exist!" << endl;
		else
		{
			boost::filesystem::remove(file_name);
			cout << "Index file removed!" << endl;
		}
	}

	db->DropTable(statement);
	cout << "Catalog written!" << endl;
	catalog_m_->WriteArchiveFile();
}