use of com.alibaba.cobar.parser.ast.fragment.VariableScope in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(MTSSetTransactionStatement node) {
appendable.append("SET ");
VariableScope scope = node.getScope();
if (scope != null) {
switch(scope) {
case SESSION:
appendable.append("SESSION ");
break;
case GLOBAL:
appendable.append("GLOBAL ");
break;
default:
throw new IllegalArgumentException("unknown scope for SET TRANSACTION ISOLATION LEVEL: " + scope);
}
}
appendable.append("TRANSACTION ISOLATION LEVEL ");
switch(node.getLevel()) {
case READ_COMMITTED:
appendable.append("READ COMMITTED");
break;
case READ_UNCOMMITTED:
appendable.append("READ UNCOMMITTED");
break;
case REPEATABLE_READ:
appendable.append("REPEATABLE READ");
break;
case SERIALIZABLE:
appendable.append("SERIALIZABLE");
break;
default:
throw new IllegalArgumentException("unknown level for SET TRANSACTION ISOLATION LEVEL: " + node.getLevel());
}
}
use of com.alibaba.cobar.parser.ast.fragment.VariableScope in project cobar by alibaba.
the class MySQLDALParser method varAssign.
private Object varAssign() throws SQLSyntaxErrorException {
VariableExpression var;
Expression expr;
VariableScope scope = VariableScope.SESSION;
switch(lexer.token()) {
case IDENTIFIER:
boolean explictScope = false;
SpecialIdentifier si = specialIdentifiers.get(lexer.stringValueUppercase());
if (si != null) {
switch(si) {
case TRANSACTION:
return setMTSSetTransactionStatement(null);
case GLOBAL:
scope = VariableScope.GLOBAL;
case SESSION:
case LOCAL:
explictScope = true;
lexer.nextToken();
default:
break;
}
}
if (explictScope && specialIdentifiers.get(lexer.stringValueUppercase()) == SpecialIdentifier.TRANSACTION) {
return setMTSSetTransactionStatement(scope);
}
var = new SysVarPrimary(scope, lexer.stringValue(), lexer.stringValueUppercase());
match(IDENTIFIER);
break;
case SYS_VAR:
var = systemVariale();
break;
case USR_VAR:
var = new UsrDefVarPrimary(lexer.stringValue());
lexer.nextToken();
break;
default:
throw err("unexpected token for SET statement");
}
match(OP_EQUALS, OP_ASSIGN);
expr = exprParser.expression();
return new Pair<VariableExpression, Expression>(var, expr);
}
use of com.alibaba.cobar.parser.ast.fragment.VariableScope in project cobar by alibaba.
the class MySQLParser method systemVariale.
/**
* first token must be {@link MySQLToken#SYS_VAR}
*/
public SysVarPrimary systemVariale() throws SQLSyntaxErrorException {
SysVarPrimary sys;
VariableScope scope = VariableScope.SESSION;
String str = lexer.stringValue();
String strUp = lexer.stringValueUppercase();
match(SYS_VAR);
SpecialIdentifier si = specialIdentifiers.get(strUp);
if (si != null) {
switch(si) {
case GLOBAL:
scope = VariableScope.GLOBAL;
case SESSION:
case LOCAL:
match(PUNC_DOT);
str = lexer.stringValue();
strUp = lexer.stringValueUppercase();
match(IDENTIFIER);
sys = new SysVarPrimary(scope, str, strUp);
sys.setCacheEvalRst(cacheEvalRst);
return sys;
}
}
sys = new SysVarPrimary(scope, str, strUp);
sys.setCacheEvalRst(cacheEvalRst);
return sys;
}
use of com.alibaba.cobar.parser.ast.fragment.VariableScope in project cobar by alibaba.
the class MySQLOutputASTVisitor method visit.
@Override
public void visit(SysVarPrimary node) {
VariableScope scope = node.getScope();
switch(scope) {
case GLOBAL:
appendable.append("@@global.");
break;
case SESSION:
appendable.append("@@");
break;
default:
throw new IllegalArgumentException("unkown scope for sysVar primary: " + scope);
}
appendable.append(node.getVarText());
}
Aggregations