use of com.alibaba.cobar.parser.ast.expression.primary.VariableExpression 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.expression.primary.VariableExpression 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);
}
Aggregations