aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/ASTUseQuery.h
blob: 873a316e653880881f25bea0ffefbe6bb23dd883 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#pragma once

#include <Parsers/IAST.h>
#include <Parsers/ASTIdentifier_fwd.h>
#include <Common/quoteString.h>
#include <IO/Operators.h>


namespace DB
{


/** USE query
  */
class ASTUseQuery : public IAST
{
public:
    IAST * database;

    String getDatabase() const
    {
        String name;
        tryGetIdentifierNameInto(database, name);
        return name;
    }

    /** Get the text that identifies this element. */
    String getID(char delim) const override { return "UseQuery" + (delim + getDatabase()); }

    ASTPtr clone() const override
    {
        auto res = std::make_shared<ASTUseQuery>(*this);
        res->children.clear();
        if (database)
            res->set(res->database, database->clone());
        return res;
    }

    QueryKind getQueryKind() const override { return QueryKind::Use; }

protected:
    void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
    {
        settings.ostr << (settings.hilite ? hilite_keyword : "") << "USE " << (settings.hilite ? hilite_none : "");
        database->formatImpl(settings, state, frame);
    }
};

}