2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/ASTSetQuery.h>
|
2017-05-23 18:24:43 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/InterpreterSetQuery.h>
|
2016-12-12 07:24:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
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);
|
2017-04-01 07:20:54 +00:00
|
|
|
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);
|
2017-04-01 07:20:54 +00:00
|
|
|
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.
|
|
|
|
*/
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|