2017-04-16 05:40:17 +00:00
|
|
|
#include <iomanip>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTInsertQuery.h>
|
2019-05-30 20:12:44 +00:00
|
|
|
#include <Parsers/ASTFunction.h>
|
2016-11-20 12:43:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-05-30 20:12:44 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-20 12:43:20 +00:00
|
|
|
void ASTInsertQuery::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
2018-05-17 15:17:07 +00:00
|
|
|
frame.need_parens = false;
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2017-11-02 14:01:11 +00:00
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "INSERT INTO ";
|
|
|
|
if (table_function)
|
2017-12-01 13:23:10 +00:00
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "FUNCTION ";
|
2017-11-02 14:01:11 +00:00
|
|
|
table_function->formatImpl(settings, state, frame);
|
2017-12-01 13:23:10 +00:00
|
|
|
}
|
2017-11-02 14:01:11 +00:00
|
|
|
else
|
|
|
|
settings.ostr << (settings.hilite ? hilite_none : "")
|
|
|
|
<< (!database.empty() ? backQuoteIfNeed(database) + "." : "") << backQuoteIfNeed(table);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (columns)
|
|
|
|
{
|
|
|
|
settings.ostr << " (";
|
|
|
|
columns->formatImpl(settings, state, frame);
|
|
|
|
settings.ostr << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (select)
|
|
|
|
{
|
|
|
|
settings.ostr << " ";
|
|
|
|
select->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!format.empty())
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " FORMAT " << (settings.hilite ? hilite_none : "") << format;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << " VALUES" << (settings.hilite ? hilite_none : "");
|
|
|
|
}
|
|
|
|
}
|
2019-02-19 19:26:41 +00:00
|
|
|
|
|
|
|
if (settings_ast)
|
|
|
|
{
|
|
|
|
settings.ostr << (settings.hilite ? hilite_keyword : "") << "SETTINGS " << (settings.hilite ? hilite_none : "");
|
|
|
|
settings_ast->formatImpl(settings, state, frame);
|
|
|
|
}
|
2016-11-20 12:43:20 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 20:12:44 +00:00
|
|
|
|
2019-05-30 21:33:06 +00:00
|
|
|
void tryFindInputFunctionImpl(const ASTPtr & ast, ASTPtr & input_function)
|
2019-05-30 20:12:44 +00:00
|
|
|
{
|
|
|
|
if (!ast)
|
|
|
|
return;
|
|
|
|
for (const auto & child : ast->children)
|
2019-05-30 21:33:06 +00:00
|
|
|
tryFindInputFunctionImpl(child, input_function);
|
2019-05-30 20:12:44 +00:00
|
|
|
|
2019-05-30 21:33:06 +00:00
|
|
|
if (const auto * table_function_ast = ast->as<ASTFunction>())
|
2019-05-30 20:12:44 +00:00
|
|
|
{
|
2019-05-30 21:33:06 +00:00
|
|
|
if (table_function_ast->name == "input")
|
2019-05-30 20:12:44 +00:00
|
|
|
{
|
|
|
|
if (input_function)
|
|
|
|
throw Exception("You can use 'input()' function only once per request.", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
input_function = ast;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 21:33:06 +00:00
|
|
|
|
|
|
|
void ASTInsertQuery::tryFindInputFunction(ASTPtr & input_function) const
|
|
|
|
{
|
|
|
|
tryFindInputFunctionImpl(select, input_function);
|
|
|
|
}
|
|
|
|
|
2016-11-20 12:43:20 +00:00
|
|
|
}
|