Search in sources :

Example 1 with DDLDropTableStatement

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

the class MySQLDDLParser method dropTable.

/**
     * <code>TABLE</code> has been consumed
     */
private DDLDropTableStatement dropTable(boolean temp) throws SQLSyntaxErrorException {
    boolean ifExists = false;
    if (lexer.token() == KW_IF) {
        lexer.nextToken();
        match(KW_EXISTS);
        ifExists = true;
    }
    Identifier tb = identifier();
    List<Identifier> list;
    if (lexer.token() != PUNC_COMMA) {
        list = new ArrayList<Identifier>(1);
        list.add(tb);
    } else {
        list = new LinkedList<Identifier>();
        list.add(tb);
        for (; lexer.token() == PUNC_COMMA; ) {
            lexer.nextToken();
            tb = identifier();
            list.add(tb);
        }
    }
    DDLDropTableStatement.Mode mode = DDLDropTableStatement.Mode.UNDEF;
    switch(lexer.token()) {
        case KW_RESTRICT:
            lexer.nextToken();
            mode = DDLDropTableStatement.Mode.RESTRICT;
            break;
        case KW_CASCADE:
            lexer.nextToken();
            mode = DDLDropTableStatement.Mode.CASCADE;
            break;
    }
    return new DDLDropTableStatement(list, temp, ifExists, mode);
}
Also used : Identifier(com.alibaba.cobar.parser.ast.expression.primary.Identifier) DDLDropTableStatement(com.alibaba.cobar.parser.ast.stmt.ddl.DDLDropTableStatement)

Aggregations

Identifier (com.alibaba.cobar.parser.ast.expression.primary.Identifier)1 DDLDropTableStatement (com.alibaba.cobar.parser.ast.stmt.ddl.DDLDropTableStatement)1