Search in sources :

Example 1 with ParamMarker

use of com.alibaba.cobar.parser.ast.expression.primary.ParamMarker in project cobar by alibaba.

the class MySQLParser method createParam.

protected ParamMarker createParam(int index) {
    ParamMarker param = new ParamMarker(index);
    param.setCacheEvalRst(cacheEvalRst);
    return param;
}
Also used : ParamMarker(com.alibaba.cobar.parser.ast.expression.primary.ParamMarker)

Example 2 with ParamMarker

use of com.alibaba.cobar.parser.ast.expression.primary.ParamMarker in project cobar by alibaba.

the class MySQLDMLParserTest method testLimit.

public void testLimit() throws SQLSyntaxErrorException {
    String sql = "limit 1,2";
    MySQLLexer lexer = new MySQLLexer(sql);
    MySQLDMLParser parser = getDMLParser(lexer);
    Limit limit = parser.limit();
    String output = output2MySQL(limit, sql);
    Assert.assertEquals(1, limit.getOffset());
    Assert.assertEquals(2, limit.getSize());
    Assert.assertEquals("LIMIT 1, 2", output);
    sql = "limit 1,?";
    lexer = new MySQLLexer(sql);
    parser = getDMLParser(lexer);
    limit = parser.limit();
    output = output2MySQL(limit, sql);
    Assert.assertEquals(1, limit.getOffset());
    Assert.assertEquals(new ParamMarker(1), limit.getSize());
    Assert.assertEquals("LIMIT 1, ?", output);
    sql = "limit ?,9";
    lexer = new MySQLLexer(sql);
    parser = getDMLParser(lexer);
    limit = parser.limit();
    output = output2MySQL(limit, sql);
    Assert.assertEquals(new ParamMarker(1), limit.getOffset());
    Assert.assertEquals(9, limit.getSize());
    Assert.assertEquals("LIMIT ?, 9", output);
    sql = "limit ?,?";
    lexer = new MySQLLexer(sql);
    parser = getDMLParser(lexer);
    limit = parser.limit();
    output = output2MySQL(limit, sql);
    Assert.assertEquals(new ParamMarker(1), limit.getOffset());
    Assert.assertEquals(new ParamMarker(2), limit.getSize());
    Assert.assertEquals("LIMIT ?, ?", output);
    sql = "limit ? d";
    lexer = new MySQLLexer(sql);
    parser = getDMLParser(lexer);
    limit = parser.limit();
    output = output2MySQL(limit, sql);
    Assert.assertEquals(0, limit.getOffset());
    Assert.assertEquals(new ParamMarker(1), limit.getSize());
    Assert.assertEquals("LIMIT 0, ?", output);
    sql = "limit 9 f";
    lexer = new MySQLLexer(sql);
    parser = getDMLParser(lexer);
    limit = parser.limit();
    output = output2MySQL(limit, sql);
    Assert.assertEquals(0, limit.getOffset());
    Assert.assertEquals(9, limit.getSize());
    Assert.assertEquals("LIMIT 0, 9", output);
    sql = "limit 9 ofFset 0";
    lexer = new MySQLLexer(sql);
    parser = getDMLParser(lexer);
    limit = parser.limit();
    output = output2MySQL(limit, sql);
    Assert.assertEquals(0, limit.getOffset());
    Assert.assertEquals(9, limit.getSize());
    Assert.assertEquals("LIMIT 0, 9", output);
    sql = "limit ? offset 0";
    lexer = new MySQLLexer(sql);
    parser = getDMLParser(lexer);
    limit = parser.limit();
    output = output2MySQL(limit, sql);
    Assert.assertEquals(0, limit.getOffset());
    Assert.assertEquals(new ParamMarker(1), limit.getSize());
    Assert.assertEquals("LIMIT 0, ?", output);
    sql = "limit ? offset ?";
    lexer = new MySQLLexer(sql);
    parser = getDMLParser(lexer);
    limit = parser.limit();
    output = output2MySQL(limit, sql);
    Assert.assertEquals(new ParamMarker(2), limit.getOffset());
    Assert.assertEquals(new ParamMarker(1), limit.getSize());
    Assert.assertEquals("LIMIT ?, ?", output);
    sql = "limit 9 offset ?";
    lexer = new MySQLLexer(sql);
    parser = getDMLParser(lexer);
    limit = parser.limit();
    output = output2MySQL(limit, sql);
    Assert.assertEquals(new ParamMarker(1), limit.getOffset());
    Assert.assertEquals(9, limit.getSize());
    Assert.assertEquals("LIMIT ?, 9", output);
}
Also used : MySQLLexer(com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer) ParamMarker(com.alibaba.cobar.parser.ast.expression.primary.ParamMarker) Limit(com.alibaba.cobar.parser.ast.fragment.Limit)

Aggregations

ParamMarker (com.alibaba.cobar.parser.ast.expression.primary.ParamMarker)2 Limit (com.alibaba.cobar.parser.ast.fragment.Limit)1 MySQLLexer (com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer)1