ClickHouse/dbms/src/Interpreters/InterpreterSetQuery.cpp

53 lines
1.6 KiB
C++
Raw Normal View History

#include <Parsers/ASTSetQuery.h>
2017-05-23 18:24:43 +00:00
#include <Interpreters/Context.h>
#include <Interpreters/InterpreterSetQuery.h>
2016-12-12 07:24:56 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int READONLY;
2016-12-12 07:24:56 +00:00
}
BlockIO InterpreterSetQuery::execute()
{
2017-05-23 18:24:43 +00:00
const ASTSetQuery & ast = typeid_cast<const ASTSetQuery &>(*query_ptr);
Context & target = ast.global ? context.getGlobalContext() : context.getSessionContext();
executeImpl(ast, target);
return {};
2016-12-12 07:24:56 +00:00
}
void InterpreterSetQuery::executeForCurrentContext()
{
2017-05-23 18:24:43 +00:00
const ASTSetQuery & ast = typeid_cast<const ASTSetQuery &>(*query_ptr);
executeImpl(ast, context);
2016-12-12 07:24:56 +00:00
}
2017-05-23 18:24:43 +00:00
void InterpreterSetQuery::executeImpl(const ASTSetQuery & ast, Context & target)
2016-12-12 07:24:56 +00:00
{
2017-04-02 17:37:49 +00:00
/** The `readonly` value is understood as follows:
* 0 - everything allowed.
* 1 - only read queries can be made; you can not change the settings.
* 2 - You can only do read queries and you can change the settings, except for the `readonly` setting.
*/
if (context.getSettingsRef().limits.readonly == 1)
throw Exception("Cannot execute SET query in readonly mode", ErrorCodes::READONLY);
if (context.getSettingsRef().limits.readonly > 1)
for (ASTSetQuery::Changes::const_iterator it = ast.changes.begin(); it != ast.changes.end(); ++it)
if (it->name == "readonly")
throw Exception("Cannot modify 'readonly' setting in readonly mode", ErrorCodes::READONLY);
for (ASTSetQuery::Changes::const_iterator it = ast.changes.begin(); it != ast.changes.end(); ++it)
target.setSetting(it->name, it->value);
2016-12-12 07:24:56 +00:00
}
}