| 1 | #include <Parsers/ASTDropQuery.h> |
|---|---|
| 2 | #include <Common/quoteString.h> |
| 3 | |
| 4 | |
| 5 | namespace DB |
| 6 | { |
| 7 | |
| 8 | namespace ErrorCodes |
| 9 | { |
| 10 | extern const int SYNTAX_ERROR; |
| 11 | } |
| 12 | |
| 13 | |
| 14 | String ASTDropQuery::getID(char delim) const |
| 15 | { |
| 16 | if (kind == ASTDropQuery::Kind::Drop) |
| 17 | return "DropQuery"+ (delim + database) + delim + table; |
| 18 | else if (kind == ASTDropQuery::Kind::Detach) |
| 19 | return "DetachQuery"+ (delim + database) + delim + table; |
| 20 | else if (kind == ASTDropQuery::Kind::Truncate) |
| 21 | return "TruncateQuery"+ (delim + database) + delim + table; |
| 22 | else |
| 23 | throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR); |
| 24 | } |
| 25 | |
| 26 | ASTPtr ASTDropQuery::clone() const |
| 27 | { |
| 28 | auto res = std::make_shared<ASTDropQuery>(*this); |
| 29 | cloneOutputOptions(*res); |
| 30 | return res; |
| 31 | } |
| 32 | |
| 33 | void ASTDropQuery::formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const |
| 34 | { |
| 35 | settings.ostr << (settings.hilite ? hilite_keyword : ""); |
| 36 | if (kind == ASTDropQuery::Kind::Drop) |
| 37 | settings.ostr << "DROP "; |
| 38 | else if (kind == ASTDropQuery::Kind::Detach) |
| 39 | settings.ostr << "DETACH "; |
| 40 | else if (kind == ASTDropQuery::Kind::Truncate) |
| 41 | settings.ostr << "TRUNCATE "; |
| 42 | else |
| 43 | throw Exception("Not supported kind of drop query.", ErrorCodes::SYNTAX_ERROR); |
| 44 | |
| 45 | if (temporary) |
| 46 | settings.ostr << "TEMPORARY "; |
| 47 | |
| 48 | if (table.empty() && !database.empty()) |
| 49 | settings.ostr << "DATABASE "; |
| 50 | else if (!is_dictionary) |
| 51 | settings.ostr << "TABLE "; |
| 52 | else |
| 53 | settings.ostr << "DICTIONARY "; |
| 54 | |
| 55 | if (if_exists) |
| 56 | settings.ostr << "IF EXISTS "; |
| 57 | |
| 58 | settings.ostr << (settings.hilite ? hilite_none : ""); |
| 59 | |
| 60 | if (table.empty() && !database.empty()) |
| 61 | settings.ostr << backQuoteIfNeed(database); |
| 62 | else |
| 63 | settings.ostr << (!database.empty() ? backQuoteIfNeed(database) + ".": "") << backQuoteIfNeed(table); |
| 64 | |
| 65 | formatOnCluster(settings); |
| 66 | } |
| 67 | |
| 68 | } |
| 69 |