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);
}
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);
}
Aggregations