Search in sources :

Example 1 with VariableScope

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());
    }
}
Also used : VariableScope(com.alibaba.cobar.parser.ast.fragment.VariableScope)

Example 2 with VariableScope

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);
}
Also used : UsrDefVarPrimary(com.alibaba.cobar.parser.ast.expression.primary.UsrDefVarPrimary) Expression(com.alibaba.cobar.parser.ast.expression.Expression) VariableExpression(com.alibaba.cobar.parser.ast.expression.primary.VariableExpression) VariableExpression(com.alibaba.cobar.parser.ast.expression.primary.VariableExpression) SysVarPrimary(com.alibaba.cobar.parser.ast.expression.primary.SysVarPrimary) VariableScope(com.alibaba.cobar.parser.ast.fragment.VariableScope) Pair(com.alibaba.cobar.parser.util.Pair)

Example 3 with VariableScope

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;
}
Also used : SysVarPrimary(com.alibaba.cobar.parser.ast.expression.primary.SysVarPrimary) VariableScope(com.alibaba.cobar.parser.ast.fragment.VariableScope)

Example 4 with VariableScope

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());
}
Also used : VariableScope(com.alibaba.cobar.parser.ast.fragment.VariableScope)

Aggregations

VariableScope (com.alibaba.cobar.parser.ast.fragment.VariableScope)4 SysVarPrimary (com.alibaba.cobar.parser.ast.expression.primary.SysVarPrimary)2 Expression (com.alibaba.cobar.parser.ast.expression.Expression)1 UsrDefVarPrimary (com.alibaba.cobar.parser.ast.expression.primary.UsrDefVarPrimary)1 VariableExpression (com.alibaba.cobar.parser.ast.expression.primary.VariableExpression)1 Pair (com.alibaba.cobar.parser.util.Pair)1