#include #include #include #include #include #include #include #include #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int SYNTAX_ERROR; extern const int THERE_IS_NO_QUERY; } BlockIO InterpreterShowCreateQuery::execute() { BlockIO res; res.in = executeImpl(); return res; } Block InterpreterShowCreateQuery::getSampleBlock() { return Block{{ ColumnString::create(), std::make_shared(), "statement"}}; } BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl() { const auto & ast = dynamic_cast(*query_ptr); if (ast.temporary && !ast.database.empty()) throw Exception("Temporary databases are not possible.", ErrorCodes::SYNTAX_ERROR); ASTPtr create_query; if (ast.temporary) create_query = context.getCreateExternalTableQuery(ast.table); else if (ast.table.empty()) create_query = context.getCreateDatabaseQuery(ast.database); else create_query = context.getCreateTableQuery(ast.database, ast.table); if (!create_query && ast.temporary) throw Exception("Unable to show the create query of " + ast.table + ". Maybe it was created by the system.", ErrorCodes::THERE_IS_NO_QUERY); std::stringstream stream; formatAST(*create_query, stream, false, true); String res = stream.str(); MutableColumnPtr column = ColumnString::create(); column->insert(res); return std::make_shared(Block{{ std::move(column), std::make_shared(), "statement"}}); } }