mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 09:02:00 +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 <Common/quoteString.h>
|
||||
#include <Common/escapeString.h>
|
||||
#include <IO/Operators.h>
|
||||
#include <IO/WriteBufferFromString.h>
|
||||
#include <Parsers/ASTShowColumnsQuery.h>
|
||||
@ -31,12 +32,8 @@ String InterpreterShowColumnsQuery::getRewrittenQuery()
|
||||
|
||||
WriteBufferFromOwnString buf_database;
|
||||
String resolved_database = getContext()->resolveDatabase(query.database);
|
||||
writeEscapedString(resolved_database, buf_database);
|
||||
String database = buf_database.str();
|
||||
|
||||
WriteBufferFromOwnString buf_table;
|
||||
writeEscapedString(query.table, buf_table);
|
||||
String table = buf_table.str();
|
||||
String database = escapeString(resolved_database);
|
||||
String table = escapeString(query.table);
|
||||
|
||||
String rewritten_query;
|
||||
if (use_mysql_types)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <Interpreters/InterpreterShowIndexesQuery.h>
|
||||
|
||||
#include <Common/quoteString.h>
|
||||
#include <Common/escapeString.h>
|
||||
#include <IO/Operators.h>
|
||||
#include <IO/WriteBufferFromString.h>
|
||||
#include <Parsers/ASTShowIndexesQuery.h>
|
||||
@ -23,16 +24,9 @@ InterpreterShowIndexesQuery::InterpreterShowIndexesQuery(const ASTPtr & query_pt
|
||||
String InterpreterShowIndexesQuery::getRewrittenQuery()
|
||||
{
|
||||
const auto & query = query_ptr->as<ASTShowIndexesQuery &>();
|
||||
|
||||
WriteBufferFromOwnString buf_table;
|
||||
writeEscapedString(query.table, buf_table);
|
||||
String table = buf_table.str();
|
||||
|
||||
WriteBufferFromOwnString buf_database;
|
||||
String table = escapeString(query.table);
|
||||
String resolved_database = getContext()->resolveDatabase(query.database);
|
||||
writeEscapedString(resolved_database, buf_database);
|
||||
String database = buf_database.str();
|
||||
|
||||
String database = escapeString(resolved_database);
|
||||
String where_expression = query.where_expression ? fmt::format("WHERE ({})", query.where_expression) : "";
|
||||
|
||||
String rewritten_query = fmt::format(R"(
|
||||
|
@ -1,10 +1,7 @@
|
||||
#include <Interpreters/InterpreterShowSettingQuery.h>
|
||||
|
||||
#include <Common/quoteString.h>
|
||||
#include <IO/Operators.h>
|
||||
#include <IO/WriteBufferFromString.h>
|
||||
#include <Common/escapeString.h>
|
||||
#include <Parsers/ASTShowSettingQuery.h>
|
||||
#include <Parsers/formatAST.h>
|
||||
#include <Interpreters/Context.h>
|
||||
#include <Interpreters/executeQuery.h>
|
||||
|
||||
@ -23,7 +20,7 @@ InterpreterShowSettingQuery::InterpreterShowSettingQuery(const ASTPtr & query_pt
|
||||
String InterpreterShowSettingQuery::getRewrittenQuery()
|
||||
{
|
||||
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/ASTIdentifier_fwd.h>
|
||||
#include <Parsers/ASTLiteral.h>
|
||||
#include <Parsers/ASTShowSettingQuery.h>
|
||||
#include <Parsers/CommonParsers.h>
|
||||
#include <Parsers/ExpressionElementParsers.h>
|
||||
#include <Parsers/ExpressionListParsers.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
@ -5,9 +5,9 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
/** Parses queries of the form
|
||||
* SHOW SETTING setting_name
|
||||
*/
|
||||
/** Parses queries of the form:
|
||||
* SHOW SETTING [setting_name]
|
||||
*/
|
||||
class ParserShowSettingQuery : public IParserBase
|
||||
{
|
||||
protected:
|
||||
|
@ -1 +1,2 @@
|
||||
1
|
||||
2
|
||||
|
@ -1,2 +1,7 @@
|
||||
SET max_threads = 1;
|
||||
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