blob: a216aeaa11f15456ef7ec44a3991c6a2ebc804aa (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ASTQueryWithTableAndOutput.h>
#include <Common/quoteString.h>
#include <IO/Operators.h>
namespace DB
{
String ASTQueryWithTableAndOutput::getDatabase() const
{
String name;
tryGetIdentifierNameInto(database, name);
return name;
}
String ASTQueryWithTableAndOutput::getTable() const
{
String name;
tryGetIdentifierNameInto(table, name);
return name;
}
void ASTQueryWithTableAndOutput::setDatabase(const String & name)
{
if (database)
{
std::erase(children, database);
database.reset();
}
if (!name.empty())
{
database = std::make_shared<ASTIdentifier>(name);
children.push_back(database);
}
}
void ASTQueryWithTableAndOutput::setTable(const String & name)
{
if (table)
{
std::erase(children, table);
table.reset();
}
if (!name.empty())
{
table = std::make_shared<ASTIdentifier>(name);
children.push_back(table);
}
}
void ASTQueryWithTableAndOutput::cloneTableOptions(ASTQueryWithTableAndOutput & cloned) const
{
if (database)
{
cloned.database = database->clone();
cloned.children.push_back(cloned.database);
}
if (table)
{
cloned.table = table->clone();
cloned.children.push_back(cloned.table);
}
}
void ASTQueryWithTableAndOutput::formatHelper(const FormatSettings & settings, const char * name) const
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << name << " " << (settings.hilite ? hilite_none : "");
settings.ostr << (database ? backQuoteIfNeed(getDatabase()) + "." : "") << backQuoteIfNeed(getTable());
}
}
|