mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Fixed code review issues
This commit is contained in:
parent
108df081b7
commit
901294d352
16
src/Common/escapeString.cpp
Normal file
16
src/Common/escapeString.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <Common/escapeString.h>
|
||||||
|
|
||||||
|
#include <IO/WriteBufferFromString.h>
|
||||||
|
#include <IO/WriteHelpers.h>
|
||||||
|
|
||||||
|
namespace DB
|
||||||
|
{
|
||||||
|
|
||||||
|
String escapeString(std::string_view value)
|
||||||
|
{
|
||||||
|
WriteBufferFromOwnString buf;
|
||||||
|
writeEscapedString(value, buf);
|
||||||
|
return buf.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
10
src/Common/escapeString.h
Normal file
10
src/Common/escapeString.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <base/types.h>
|
||||||
|
|
||||||
|
namespace DB
|
||||||
|
{
|
||||||
|
|
||||||
|
String escapeString(std::string_view value);
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#include <Interpreters/InterpreterShowColumnsQuery.h>
|
#include <Interpreters/InterpreterShowColumnsQuery.h>
|
||||||
|
|
||||||
#include <Common/quoteString.h>
|
#include <Common/quoteString.h>
|
||||||
|
#include <Common/escapeString.h>
|
||||||
#include <IO/Operators.h>
|
#include <IO/Operators.h>
|
||||||
#include <IO/WriteBufferFromString.h>
|
#include <IO/WriteBufferFromString.h>
|
||||||
#include <Parsers/ASTShowColumnsQuery.h>
|
#include <Parsers/ASTShowColumnsQuery.h>
|
||||||
@ -31,12 +32,8 @@ String InterpreterShowColumnsQuery::getRewrittenQuery()
|
|||||||
|
|
||||||
WriteBufferFromOwnString buf_database;
|
WriteBufferFromOwnString buf_database;
|
||||||
String resolved_database = getContext()->resolveDatabase(query.database);
|
String resolved_database = getContext()->resolveDatabase(query.database);
|
||||||
writeEscapedString(resolved_database, buf_database);
|
String database = escapeString(resolved_database);
|
||||||
String database = buf_database.str();
|
String table = escapeString(query.table);
|
||||||
|
|
||||||
WriteBufferFromOwnString buf_table;
|
|
||||||
writeEscapedString(query.table, buf_table);
|
|
||||||
String table = buf_table.str();
|
|
||||||
|
|
||||||
String rewritten_query;
|
String rewritten_query;
|
||||||
if (use_mysql_types)
|
if (use_mysql_types)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <Interpreters/InterpreterShowIndexesQuery.h>
|
#include <Interpreters/InterpreterShowIndexesQuery.h>
|
||||||
|
|
||||||
#include <Common/quoteString.h>
|
#include <Common/quoteString.h>
|
||||||
|
#include <Common/escapeString.h>
|
||||||
#include <IO/Operators.h>
|
#include <IO/Operators.h>
|
||||||
#include <IO/WriteBufferFromString.h>
|
#include <IO/WriteBufferFromString.h>
|
||||||
#include <Parsers/ASTShowIndexesQuery.h>
|
#include <Parsers/ASTShowIndexesQuery.h>
|
||||||
@ -23,16 +24,9 @@ InterpreterShowIndexesQuery::InterpreterShowIndexesQuery(const ASTPtr & query_pt
|
|||||||
String InterpreterShowIndexesQuery::getRewrittenQuery()
|
String InterpreterShowIndexesQuery::getRewrittenQuery()
|
||||||
{
|
{
|
||||||
const auto & query = query_ptr->as<ASTShowIndexesQuery &>();
|
const auto & query = query_ptr->as<ASTShowIndexesQuery &>();
|
||||||
|
String table = escapeString(query.table);
|
||||||
WriteBufferFromOwnString buf_table;
|
|
||||||
writeEscapedString(query.table, buf_table);
|
|
||||||
String table = buf_table.str();
|
|
||||||
|
|
||||||
WriteBufferFromOwnString buf_database;
|
|
||||||
String resolved_database = getContext()->resolveDatabase(query.database);
|
String resolved_database = getContext()->resolveDatabase(query.database);
|
||||||
writeEscapedString(resolved_database, buf_database);
|
String database = escapeString(resolved_database);
|
||||||
String database = buf_database.str();
|
|
||||||
|
|
||||||
String where_expression = query.where_expression ? fmt::format("WHERE ({})", query.where_expression) : "";
|
String where_expression = query.where_expression ? fmt::format("WHERE ({})", query.where_expression) : "";
|
||||||
|
|
||||||
String rewritten_query = fmt::format(R"(
|
String rewritten_query = fmt::format(R"(
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
#include <Interpreters/InterpreterShowSettingQuery.h>
|
#include <Interpreters/InterpreterShowSettingQuery.h>
|
||||||
|
|
||||||
#include <Common/quoteString.h>
|
#include <Common/escapeString.h>
|
||||||
#include <IO/Operators.h>
|
|
||||||
#include <IO/WriteBufferFromString.h>
|
|
||||||
#include <Parsers/ASTShowSettingQuery.h>
|
#include <Parsers/ASTShowSettingQuery.h>
|
||||||
#include <Parsers/formatAST.h>
|
|
||||||
#include <Interpreters/Context.h>
|
#include <Interpreters/Context.h>
|
||||||
#include <Interpreters/executeQuery.h>
|
#include <Interpreters/executeQuery.h>
|
||||||
|
|
||||||
@ -23,7 +20,7 @@ InterpreterShowSettingQuery::InterpreterShowSettingQuery(const ASTPtr & query_pt
|
|||||||
String InterpreterShowSettingQuery::getRewrittenQuery()
|
String InterpreterShowSettingQuery::getRewrittenQuery()
|
||||||
{
|
{
|
||||||
const auto & query = query_ptr->as<ASTShowSettingQuery &>();
|
const auto & query = query_ptr->as<ASTShowSettingQuery &>();
|
||||||
return fmt::format(R"(SELECT value FROM system.settings WHERE name = '{0}')", query.getSettingName());
|
return fmt::format(R"(SELECT value FROM system.settings WHERE name = '{0}')", escapeString(query.getSettingName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
#include <Parsers/ParserShowSettingQuery.h>
|
#include <Parsers/ParserShowSettingQuery.h>
|
||||||
|
|
||||||
#include <Parsers/ASTIdentifier_fwd.h>
|
#include <Parsers/ASTIdentifier_fwd.h>
|
||||||
#include <Parsers/ASTLiteral.h>
|
|
||||||
#include <Parsers/ASTShowSettingQuery.h>
|
#include <Parsers/ASTShowSettingQuery.h>
|
||||||
#include <Parsers/CommonParsers.h>
|
#include <Parsers/CommonParsers.h>
|
||||||
#include <Parsers/ExpressionElementParsers.h>
|
#include <Parsers/ExpressionElementParsers.h>
|
||||||
#include <Parsers/ExpressionListParsers.h>
|
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
|
||||||
/** Parses queries of the form
|
/** Parses queries of the form:
|
||||||
* SHOW SETTING setting_name
|
* SHOW SETTING [setting_name]
|
||||||
*/
|
*/
|
||||||
class ParserShowSettingQuery : public IParserBase
|
class ParserShowSettingQuery : public IParserBase
|
||||||
{
|
{
|
||||||
|
@ -1 +1,2 @@
|
|||||||
1
|
1
|
||||||
|
2
|
||||||
|
@ -1,2 +1,7 @@
|
|||||||
SET max_threads = 1;
|
SET max_threads = 1;
|
||||||
SHOW SETTING max_threads;
|
SHOW SETTING max_threads;
|
||||||
|
|
||||||
|
SET max_threads = 2;
|
||||||
|
SHOW SETTING max_threads;
|
||||||
|
|
||||||
|
SHOW SETTING `max_threads' OR name = 'max_memory_usage`;
|
||||||
|
Loading…
Reference in New Issue
Block a user