mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-01 03:52:15 +00:00
32 lines
1.0 KiB
C++
32 lines
1.0 KiB
C++
#include <Parsers/getInsertQuery.h>
|
|
|
|
#include <Parsers/ASTInsertQuery.h>
|
|
#include <Parsers/ASTIdentifier.h>
|
|
#include <Parsers/ASTExpressionList.h>
|
|
#include <IO/WriteBufferFromString.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
std::string getInsertQuery(const std::string & db_name, const std::string & table_name, const ColumnsWithTypeAndName & columns, IdentifierQuotingStyle quoting)
|
|
{
|
|
ASTInsertQuery query;
|
|
query.table_id.database_name = db_name;
|
|
query.table_id.table_name = table_name;
|
|
query.columns = std::make_shared<ASTExpressionList>(',');
|
|
query.children.push_back(query.columns);
|
|
for (const auto & column : columns)
|
|
query.columns->children.emplace_back(std::make_shared<ASTIdentifier>(column.name));
|
|
|
|
WriteBufferFromOwnString buf;
|
|
IAST::FormatSettings settings(
|
|
/*ostr_=*/buf,
|
|
/*one_line=*/true,
|
|
/*hilite=*/false,
|
|
/*identifier_quoting_rule=*/IdentifierQuotingRule::WhenNecessary,
|
|
/*identifier_quoting_style=*/quoting);
|
|
query.IAST::format(settings);
|
|
return buf.str();
|
|
}
|
|
}
|