ISSUES-2260 add some improvements

This commit is contained in:
zhang2014 2018-05-21 11:01:38 +08:00
parent fa865636ce
commit 3afb33593a

View File

@ -135,7 +135,8 @@ public:
/// Get the CREATE DATABASE query for current database. /// Get the CREATE DATABASE query for current database.
virtual ASTPtr getCreateDatabaseQuery(const Context & context) const = 0; virtual ASTPtr getCreateDatabaseQuery(const Context & context) const = 0;
virtual String getDatabaseName() const { return {}; } /// Get name of database.
virtual String getDatabaseName() const = 0;
/// Returns path for persistent data storage if the database supports it, empty string otherwise /// Returns path for persistent data storage if the database supports it, empty string otherwise
virtual String getDataPath() const { return {}; } virtual String getDataPath() const { return {}; }
/// Returns metadata path if the database supports it, empty string otherwise /// Returns metadata path if the database supports it, empty string otherwise
@ -146,10 +147,13 @@ public:
/// Ask all tables to complete the background threads they are using and delete all table objects. /// Ask all tables to complete the background threads they are using and delete all table objects.
virtual void shutdown() = 0; virtual void shutdown() = 0;
/// Delete metadata, the deletion of which differs from the recursive deletion of the directory, if any. /// Delete database metadata, if exists.
virtual void drop(Context & context) virtual void drop(Context & context)
{ {
String database_name = getDatabaseName(); String database_name = getDatabaseName();
if (!database_name.empty())
{
String database_name_escaped = escapeForFileName(database_name); String database_name_escaped = escapeForFileName(database_name);
Poco::File(context.getPath() + "metadata/" + database_name_escaped + "/").remove(false); Poco::File(context.getPath() + "metadata/" + database_name_escaped + "/").remove(false);
@ -158,6 +162,7 @@ public:
Poco::File database_metadata_file(context.getPath() + "metadata/" + database_name_escaped + ".sql"); Poco::File database_metadata_file(context.getPath() + "metadata/" + database_name_escaped + ".sql");
if (database_metadata_file.exists()) if (database_metadata_file.exists())
database_metadata_file.remove(false); database_metadata_file.remove(false);
}
}; };
virtual ~IDatabase() {} virtual ~IDatabase() {}