Search in sources :

Example 1 with DALSetNamesStatement

use of com.alibaba.cobar.parser.ast.stmt.dal.DALSetNamesStatement in project cobar by alibaba.

the class MySQLDALParser method set.

/**
 * @return {@link DALSetStatement} or {@link MTSSetTransactionStatement}
 */
@SuppressWarnings("unchecked")
public SQLStatement set() throws SQLSyntaxErrorException {
    match(KW_SET);
    if (lexer.token() == KW_OPTION) {
        lexer.nextToken();
    }
    if (lexer.token() == IDENTIFIER && SpecialIdentifier.NAMES == specialIdentifiers.get(lexer.stringValueUppercase())) {
        if (lexer.nextToken() == KW_DEFAULT) {
            lexer.nextToken();
            return new DALSetNamesStatement();
        }
        String charsetName = getStringValue();
        String collationName = null;
        if (lexer.token() == KW_COLLATE) {
            lexer.nextToken();
            collationName = getStringValue();
        }
        return new DALSetNamesStatement(charsetName, collationName);
    } else if (lexer.token() == KW_CHARACTER) {
        lexer.nextToken();
        match(KW_SET);
        if (lexer.token() == KW_DEFAULT) {
            lexer.nextToken();
            return new DALSetCharacterSetStatement();
        }
        String charsetName = getStringValue();
        return new DALSetCharacterSetStatement(charsetName);
    }
    List<Pair<VariableExpression, Expression>> assignmentList;
    Object obj = varAssign();
    if (obj instanceof MTSSetTransactionStatement) {
        return (MTSSetTransactionStatement) obj;
    }
    Pair<VariableExpression, Expression> pair = (Pair<VariableExpression, Expression>) obj;
    if (lexer.token() != PUNC_COMMA) {
        assignmentList = new ArrayList<Pair<VariableExpression, Expression>>(1);
        assignmentList.add(pair);
        return new DALSetStatement(assignmentList);
    }
    assignmentList = new LinkedList<Pair<VariableExpression, Expression>>();
    assignmentList.add(pair);
    for (; lexer.token() == PUNC_COMMA; ) {
        lexer.nextToken();
        pair = (Pair<VariableExpression, Expression>) varAssign();
        assignmentList.add(pair);
    }
    return new DALSetStatement(assignmentList);
}
Also used : DALSetNamesStatement(com.alibaba.cobar.parser.ast.stmt.dal.DALSetNamesStatement) VariableExpression(com.alibaba.cobar.parser.ast.expression.primary.VariableExpression) LiteralString(com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString) MTSSetTransactionStatement(com.alibaba.cobar.parser.ast.stmt.mts.MTSSetTransactionStatement) Expression(com.alibaba.cobar.parser.ast.expression.Expression) VariableExpression(com.alibaba.cobar.parser.ast.expression.primary.VariableExpression) DALSetCharacterSetStatement(com.alibaba.cobar.parser.ast.stmt.dal.DALSetCharacterSetStatement) DALSetStatement(com.alibaba.cobar.parser.ast.stmt.dal.DALSetStatement) Pair(com.alibaba.cobar.parser.util.Pair)

Aggregations

Expression (com.alibaba.cobar.parser.ast.expression.Expression)1 VariableExpression (com.alibaba.cobar.parser.ast.expression.primary.VariableExpression)1 LiteralString (com.alibaba.cobar.parser.ast.expression.primary.literal.LiteralString)1 DALSetCharacterSetStatement (com.alibaba.cobar.parser.ast.stmt.dal.DALSetCharacterSetStatement)1 DALSetNamesStatement (com.alibaba.cobar.parser.ast.stmt.dal.DALSetNamesStatement)1 DALSetStatement (com.alibaba.cobar.parser.ast.stmt.dal.DALSetStatement)1 MTSSetTransactionStatement (com.alibaba.cobar.parser.ast.stmt.mts.MTSSetTransactionStatement)1 Pair (com.alibaba.cobar.parser.util.Pair)1