use of com.alibaba.cobar.parser.ast.stmt.dml.DMLCallStatement in project cobar by alibaba.
the class MySQLDMLCallParser method call.
public DMLCallStatement call() throws SQLSyntaxErrorException {
match(KW_CALL);
Identifier procedure = identifier();
match(PUNC_LEFT_PAREN);
if (lexer.token() == PUNC_RIGHT_PAREN) {
lexer.nextToken();
return new DMLCallStatement(procedure);
}
List<Expression> arguments;
Expression expr = exprParser.expression();
switch(lexer.token()) {
case PUNC_COMMA:
arguments = new LinkedList<Expression>();
arguments.add(expr);
for (; lexer.token() == PUNC_COMMA; ) {
lexer.nextToken();
expr = exprParser.expression();
arguments.add(expr);
}
match(PUNC_RIGHT_PAREN);
return new DMLCallStatement(procedure, arguments);
case PUNC_RIGHT_PAREN:
lexer.nextToken();
arguments = new ArrayList<Expression>(1);
arguments.add(expr);
return new DMLCallStatement(procedure, arguments);
default:
throw err("expect ',' or ')' after first argument of procedure");
}
}
use of com.alibaba.cobar.parser.ast.stmt.dml.DMLCallStatement in project cobar by alibaba.
the class MySQLDMLCallParserTest method testCall.
public void testCall() throws SQLSyntaxErrorException {
String sql = "call p(?,?) ";
MySQLLexer lexer = new MySQLLexer(sql);
MySQLDMLCallParser parser = new MySQLDMLCallParser(lexer, new MySQLExprParser(lexer));
DMLCallStatement calls = parser.call();
parser.match(MySQLToken.EOF);
String output = output2MySQL(calls, sql);
Assert.assertEquals("CALL p(?, ?)", output);
sql = "call p(@var1,'@var2',var3)";
lexer = new MySQLLexer(sql);
parser = new MySQLDMLCallParser(lexer, new MySQLExprParser(lexer));
calls = parser.call();
parser.match(MySQLToken.EOF);
output = output2MySQL(calls, sql);
Assert.assertEquals("CALL p(@var1, '@var2', var3)", output);
sql = "call p()";
lexer = new MySQLLexer(sql);
parser = new MySQLDMLCallParser(lexer, new MySQLExprParser(lexer));
calls = parser.call();
parser.match(MySQLToken.EOF);
output = output2MySQL(calls, sql);
Assert.assertEquals("CALL p()", output);
sql = "call p(?)";
lexer = new MySQLLexer(sql);
parser = new MySQLDMLCallParser(lexer, new MySQLExprParser(lexer));
calls = parser.call();
parser.match(MySQLToken.EOF);
output = output2MySQL(calls, sql);
Assert.assertEquals("CALL p(?)", output);
}
Aggregations