Search in sources :

Example 1 with DDLTruncateStatement

use of com.alibaba.cobar.parser.ast.stmt.ddl.DDLTruncateStatement in project cobar by alibaba.

the class MySQLDDLParser method truncate.

public DDLTruncateStatement truncate() throws SQLSyntaxErrorException {
    matchIdentifier("TRUNCATE");
    if (lexer.token() == KW_TABLE) {
        lexer.nextToken();
    }
    Identifier tb = identifier();
    return new DDLTruncateStatement(tb);
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) DDLTruncateStatement(com.alibaba.cobar.parser.ast.stmt.ddl.DDLTruncateStatement)

Example 2 with DDLTruncateStatement

use of com.alibaba.cobar.parser.ast.stmt.ddl.DDLTruncateStatement in project cobar by alibaba.

the class MySQLDDLParserTest method testTruncate.

public void testTruncate() throws Exception {
    String sql = "Truncate table tb1";
    MySQLLexer lexer = new MySQLLexer(sql);
    MySQLDDLParser parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
    DDLStatement trun = (DDLTruncateStatement) parser.truncate();
    parser.match(MySQLToken.EOF);
    String output = output2MySQL(trun, sql);
    Assert.assertEquals("TRUNCATE TABLE tb1", output);
    sql = "Truncate tb1";
    lexer = new MySQLLexer(sql);
    parser = new MySQLDDLParser(lexer, new MySQLExprParser(lexer));
    trun = (DDLTruncateStatement) parser.truncate();
    parser.match(MySQLToken.EOF);
    output = output2MySQL(trun, sql);
    Assert.assertEquals("TRUNCATE TABLE tb1", output);
}
Also used : MySQLLexer(com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer) DDLStatement(com.alibaba.cobar.parser.ast.stmt.ddl.DDLStatement) DDLTruncateStatement(com.alibaba.cobar.parser.ast.stmt.ddl.DDLTruncateStatement)

Aggregations

DDLTruncateStatement (com.alibaba.cobar.parser.ast.stmt.ddl.DDLTruncateStatement)2 Identifier (com.alibaba.cobar.parser.ast.expression.primary.Identifier)1 DDLStatement (com.alibaba.cobar.parser.ast.stmt.ddl.DDLStatement)1 MySQLLexer (com.alibaba.cobar.parser.recognizer.mysql.lexer.MySQLLexer)1