Fixed code review issues

This commit is contained in:
Maksim Kita 2023-10-25 21:41:26 +03:00
parent 108df081b7
commit 901294d352
9 changed files with 43 additions and 26 deletions

View 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
View File

@ -0,0 +1,10 @@
#pragma once
#include <base/types.h>
namespace DB
{
String escapeString(std::string_view value);
}

View File

@ -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)

View File

@ -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"(

View File

@ -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()));
}

View File

@ -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
{

View File

@ -5,8 +5,8 @@
namespace DB
{
/** Parses queries of the form
* SHOW SETTING setting_name
/** Parses queries of the form:
* SHOW SETTING [setting_name]
*/
class ParserShowSettingQuery : public IParserBase
{

View File

@ -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`;