2021-03-31 17:55:04 +00:00
|
|
|
#include <Parsers/ParserTransactionControl.h>
|
|
|
|
#include <Parsers/ASTTransactionControl.h>
|
|
|
|
#include <Parsers/CommonParsers.h>
|
2022-03-18 13:33:59 +00:00
|
|
|
#include <Parsers/ExpressionElementParsers.h>
|
|
|
|
#include <Parsers/ASTLiteral.h>
|
2021-03-31 17:55:04 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
bool ParserTransactionControl::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
ASTTransactionControl::QueryType action;
|
2022-03-18 13:33:59 +00:00
|
|
|
UInt64 snapshot = 0;
|
2021-03-31 17:55:04 +00:00
|
|
|
|
|
|
|
if (ParserKeyword("BEGIN TRANSACTION").ignore(pos, expected))
|
|
|
|
action = ASTTransactionControl::BEGIN;
|
|
|
|
else if (ParserKeyword("COMMIT").ignore(pos, expected))
|
|
|
|
action = ASTTransactionControl::COMMIT;
|
|
|
|
else if (ParserKeyword("ROLLBACK").ignore(pos, expected))
|
|
|
|
action = ASTTransactionControl::ROLLBACK;
|
2022-03-18 13:33:59 +00:00
|
|
|
else if (ParserKeyword("SET TRANSACTION SNAPSHOT").ignore(pos, expected))
|
|
|
|
{
|
|
|
|
action = ASTTransactionControl::SET_SNAPSHOT;
|
|
|
|
ASTPtr ast;
|
|
|
|
if (!ParserNumber{}.parse(pos, ast, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const auto & snapshot_num = ast->as<ASTLiteral>()->value;
|
|
|
|
if (!snapshot_num.tryGet(snapshot))
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-31 17:55:04 +00:00
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
2022-03-18 13:33:59 +00:00
|
|
|
auto ast = std::make_shared<ASTTransactionControl>(action);
|
|
|
|
ast->snapshot = snapshot;
|
|
|
|
node = ast;
|
2021-03-31 17:55:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|