use of com.alibaba.cobar.parser.ast.expression.misc.UserExpression in project cobar by alibaba.
the class MySQLExprParser method userExpression.
private Expression userExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
Expression first = primaryExpression(consumed, consumedUp);
if (lexer.token() == USR_VAR) {
if (first instanceof LiteralString) {
StringBuilder str = new StringBuilder().append('\'').append(((LiteralString) first).getString()).append('\'').append(lexer.stringValue());
lexer.nextToken();
return new UserExpression(str.toString()).setCacheEvalRst(cacheEvalRst);
} else if (first instanceof Identifier) {
StringBuilder str = new StringBuilder().append(((Identifier) first).getIdText()).append(lexer.stringValue());
lexer.nextToken();
return new UserExpression(str.toString()).setCacheEvalRst(cacheEvalRst);
}
}
return first;
}
use of com.alibaba.cobar.parser.ast.expression.misc.UserExpression in project cobar by alibaba.
the class MySQLExprParser method collateExpression.
private Expression collateExpression(String consumed, String consumedUp) throws SQLSyntaxErrorException {
for (Expression expr = userExpression(consumed, consumedUp); ; ) {
if (lexer.token() == KW_COLLATE) {
lexer.nextToken();
String collateName = lexer.stringValue();
match(IDENTIFIER);
expr = new CollateExpression(expr, collateName).setCacheEvalRst(cacheEvalRst);
continue;
}
return expr;
}
}
use of com.alibaba.cobar.parser.ast.expression.misc.UserExpression in project cobar by alibaba.
the class MySQLExprParserTest method testUser.
public void testUser() throws Exception {
String sql = "'root'@'localhost'";
MySQLExprParser parser = new MySQLExprParser(new MySQLLexer(sql));
Expression expr = parser.expression();
String output = output2MySQL(expr, sql);
Assert.assertEquals("'root'@'localhost'", output);
UserExpression usr = (UserExpression) expr;
Assert.assertEquals("'root'@'localhost'", usr.getUserAtHost());
sql = "root@localhost";
parser = new MySQLExprParser(new MySQLLexer(sql));
expr = parser.expression();
output = output2MySQL(expr, sql);
Assert.assertEquals("root@localhost", output);
usr = (UserExpression) expr;
Assert.assertEquals("root@localhost", usr.getUserAtHost());
sql = "var@'localhost'";
parser = new MySQLExprParser(new MySQLLexer(sql));
expr = parser.expression();
output = output2MySQL(expr, sql);
Assert.assertEquals("var@'localhost'", output);
usr = (UserExpression) expr;
Assert.assertEquals("var@'localhost'", usr.getUserAtHost());
}
Aggregations