1#pragma once
2
3#include <Databases/IDatabase.h>
4#include <Interpreters/IInterpreter.h>
5#include <Parsers/ASTDropQuery.h>
6#include <Parsers/IAST_fwd.h>
7
8
9namespace DB
10{
11class Context;
12using DatabaseAndTable = std::pair<DatabasePtr, StoragePtr>;
13
14/** Allow to either drop table with all its data (DROP),
15 * or remove information about table (just forget) from server (DETACH),
16 * or just clear all data in table (TRUNCATE).
17 */
18class InterpreterDropQuery : public IInterpreter
19{
20public:
21 InterpreterDropQuery(const ASTPtr & query_ptr_, Context & context_);
22
23 /// Drop table or database.
24 BlockIO execute() override;
25
26private:
27 void checkAccess(const ASTDropQuery & drop);
28 ASTPtr query_ptr;
29 Context & context;
30
31 BlockIO executeToDatabase(String & database_name, ASTDropQuery::Kind kind, bool if_exists);
32
33 BlockIO executeToTable(String & database_name, String & table_name, ASTDropQuery::Kind kind, bool if_exists, bool if_temporary, bool no_ddl_lock);
34
35 BlockIO executeToDictionary(String & database_name, String & table_name, ASTDropQuery::Kind kind, bool if_exists, bool if_temporary, bool no_ddl_lock);
36
37 DatabasePtr tryGetDatabase(String & database_name, bool exists);
38
39 DatabaseAndTable tryGetDatabaseAndTable(String & database_name, String & table_name, bool if_exists);
40
41 BlockIO executeToTemporaryTable(String & table_name, ASTDropQuery::Kind kind);
42};
43}
44