Package com.alibaba.druid.sql.ast.statement

Examples of com.alibaba.druid.sql.ast.statement.SQLColumnDefinition


    public SQLDDLParser(Lexer lexer){
        super(lexer);
    }

    protected SQLColumnDefinition parseColumn() {
        SQLColumnDefinition column = new SQLColumnDefinition();
        column.setName(this.exprParser.name());
        column.setDataType(this.exprParser.parseDataType());

        return parseColumnRest(column);
    }
View Full Code Here


        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();

            while (lexer.token() == Token.IDENTIFIER) {
                SQLColumnDefinition column = parseColumn();
                createTable.getTableElementList().add(column);

                // parseConstaint(column.getConstaints());

                if (lexer.token() != Token.COMMA) {
View Full Code Here

                    lexer.nextToken();

                    if (identifierEquals("COLUMN")) {
                        lexer.nextToken();
                        MySqlAlterTableAddColumn item = new MySqlAlterTableAddColumn();
                        SQLColumnDefinition columnDef = this.exprParser.parseColumn();
                        item.getColumns().add(columnDef);
                        if (identifierEquals("AFTER")) {
                            lexer.nextToken();
                            item.setAfterColumn(this.exprParser.name());
                        } else if (identifierEquals("FIRST")) {
                            lexer.nextToken();
                            if (lexer.token() == Token.IDENTIFIER) {
                                item.setFirstColumn(this.exprParser.name());
                            } else {
                                item.setFirst(true);
                            }
                        }
                        stmt.getItems().add(item);
                    } else if (lexer.token() == Token.INDEX) {
                        lexer.nextToken();
                        MySqlAlterTableAddIndex item = new MySqlAlterTableAddIndex();

                        if (lexer.token() == Token.LPAREN) {
                            lexer.nextToken();
                        } else {
                            item.setName(this.exprParser.name());
                            accept(Token.LPAREN);
                        }

                        for (;;) {
                            SQLSelectOrderByItem column = this.exprParser.parseSelectOrderByItem();
                            item.getItems().add(column);
                            if (lexer.token() == Token.COMMA) {
                                lexer.nextToken();
                                continue;
                            }
                            break;
                        }
                        accept(Token.RPAREN);

                        stmt.getItems().add(item);
                    } else if (lexer.token() == Token.UNIQUE) {
                        lexer.nextToken();

                        if (lexer.token() == Token.INDEX) {
                            lexer.nextToken();
                        }

                        MySqlAlterTableAddUnique item = new MySqlAlterTableAddUnique();

                        if (lexer.token() == Token.LPAREN) {
                            lexer.nextToken();
                        } else {
                            item.setName(this.exprParser.name());
                            accept(Token.LPAREN);
                        }

                        for (;;) {
                            SQLSelectOrderByItem column = this.exprParser.parseSelectOrderByItem();
                            item.getItems().add(column);
                            if (lexer.token() == Token.COMMA) {
                                lexer.nextToken();
                                continue;
                            }
                            break;
                        }
                        accept(Token.RPAREN);

                        stmt.getItems().add(item);
                    } else if (lexer.token() == Token.PRIMARY) {
                        SQLPrimaryKey primaryKey = ((MySqlExprParser) this.exprParser).parsePrimaryKey();
                        SQLAlterTableAddPrimaryKey item = new SQLAlterTableAddPrimaryKey();
                        item.setPrimaryKey(primaryKey);
                        stmt.getItems().add(item);
                    } else if (lexer.token() == Token.KEY) {
                        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
                    } else if (lexer.token() == Token.CONSTRAINT) {
                        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
                    } else if (identifierEquals(FULLTEXT)) {
                        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
                    } else if (identifierEquals(SPATIAL)) {
                        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
                    } else {
                        MySqlAlterTableAddColumn item = new MySqlAlterTableAddColumn();
                        SQLColumnDefinition columnDef = this.exprParser.parseColumn();
                        item.getColumns().add(columnDef);
                        if (identifierEquals("AFTER")) {
                            lexer.nextToken();
                            item.setAfterColumn(this.exprParser.name());
                        }
View Full Code Here

                                        + lexer.stringVal());
        }
    }

    public SQLColumnDefinition parseColumn() {
        SQLColumnDefinition column = new SQLColumnDefinition();
        column.setName(name());
        column.setDataType(parseDataType());

        return parseColumnRest(column);
    }
View Full Code Here

        if (lexer.token() == (Token.LPAREN)) {
            lexer.nextToken();

            for (;;) {
                if (lexer.token() == Token.IDENTIFIER) {
                    SQLColumnDefinition column = this.exprParser.parseColumn();
                    stmt.getTableElementList().add(column);
                } else if (lexer.token() == (Token.CONSTRAINT)) {
                    stmt.getTableElementList().add(parseConstraint());
                } else if (lexer.token() == (Token.INDEX)) {
                    lexer.nextToken();
View Full Code Here

                    lexer.nextToken();

                    SQLAlterTableAddColumn item = new SQLAlterTableAddColumn();

                    for (;;) {
                        SQLColumnDefinition columnDef = this.exprParser.parseColumn();
                        item.getColumns().add(columnDef);
                        if (lexer.token() == Token.COMMA) {
                            lexer.nextToken();
                            continue;
                        }
                        break;
                    }
                    accept(Token.RPAREN);

                    stmt.getItems().add(item);
                } else if (lexer.token() == Token.CONSTRAINT) {
                    stmt.getItems().add(parseConstaint());
                } else {
                    throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
                }

                continue;
            } else if (identifierEquals("MOVE")) {
                lexer.nextToken();

                if (identifierEquals("TABLESPACE")) {
                    lexer.nextToken();

                    OracleAlterTableMoveTablespace item = new OracleAlterTableMoveTablespace();
                    item.setName(this.exprParser.name());

                    stmt.getItems().add(item);
                } else {
                    throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
                }
            } else if (identifierEquals("RENAME")) {
                stmt.getItems().add(parseAlterTableRename());
            } else if (identifierEquals("MODIFY")) {
                lexer.nextToken();

                if (lexer.token() == Token.LPAREN) {
                    lexer.nextToken();
                    OracleAlterTableModify item = new OracleAlterTableModify();

                    for (;;) {
                        SQLColumnDefinition columnDef = this.exprParser.parseColumn();
                        item.getColumns().add(columnDef);
                        if (lexer.token() == Token.COMMA) {
                            lexer.nextToken();
                            continue;
                        }
View Full Code Here

                    lexer.nextToken();

                    if (lexer.token() == Token.COLUMN) {
                        lexer.nextToken();
                        MySqlAlterTableAddColumn item = new MySqlAlterTableAddColumn();
                        SQLColumnDefinition columnDef = this.exprParser.parseColumn();
                        item.getColumns().add(columnDef);
                        if (identifierEquals("AFTER")) {
                            lexer.nextToken();
                            item.setAfterColumn(this.exprParser.name());
                        } else if (identifierEquals("FIRST")) {
                            lexer.nextToken();
                            if (lexer.token() == Token.IDENTIFIER) {
                                item.setFirstColumn(this.exprParser.name());
                            } else {
                                item.setFirst(true);
                            }
                        }
                        stmt.getItems().add(item);
                    } else if (lexer.token() == Token.INDEX) {
                        SQLAlterTableAddIndex item = parseAlterTableAddIndex();
                        item.setParent(stmt);
                        stmt.getItems().add(item);
                    } else if (lexer.token() == Token.UNIQUE) {
                        SQLAlterTableAddIndex item = parseAlterTableAddIndex();
                        item.setParent(stmt);
                        stmt.getItems().add(item);
                    } else if (lexer.token() == Token.PRIMARY) {
                        SQLPrimaryKey primaryKey = this.exprParser.parsePrimaryKey();
                        SQLAlterTableAddConstraint item = new SQLAlterTableAddConstraint(primaryKey);
                        stmt.getItems().add(item);
                    } else if (lexer.token() == Token.KEY) {
                        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
                    } else if (lexer.token() == Token.CONSTRAINT) {
                        lexer.nextToken();
                        SQLName constraintName = this.exprParser.name();

                        if (lexer.token() == Token.PRIMARY) {
                            SQLPrimaryKey primaryKey = ((MySqlExprParser) this.exprParser).parsePrimaryKey();

                            primaryKey.setName(constraintName);

                            SQLAlterTableAddConstraint item = new SQLAlterTableAddConstraint(primaryKey);
                            item.setParent(stmt);

                            stmt.getItems().add(item);
                        } else if (lexer.token() == Token.FOREIGN) {
                            MysqlForeignKey fk = this.getExprParser().parseForeignKey();
                            fk.setName(constraintName);
                            fk.setHasConstraint(true);

                            SQLAlterTableAddConstraint item = new SQLAlterTableAddConstraint(fk);

                            item.setParent(stmt);

                            stmt.getItems().add(item);
                        } else {
                            throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
                        }
                    } else if (identifierEquals(FULLTEXT)) {
                        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
                    } else if (identifierEquals(SPATIAL)) {
                        throw new ParserException("TODO " + lexer.token() + " " + lexer.stringVal());
                    } else {
                        MySqlAlterTableAddColumn item = new MySqlAlterTableAddColumn();
                        SQLColumnDefinition columnDef = this.exprParser.parseColumn();
                        item.getColumns().add(columnDef);
                        if (identifierEquals("AFTER")) {
                            lexer.nextToken();
                            item.setAfterColumn(this.exprParser.name());
                        }
                        stmt.getItems().add(item);
                    }
                } else if (lexer.token() == Token.ALTER) {
                    lexer.nextToken();
                    if (lexer.token() == Token.COLUMN) {
                        lexer.nextToken();
                    }

                    SQLAlterTableAlterColumn alterColumn = new SQLAlterTableAlterColumn();
                    SQLColumnDefinition columnDef = this.exprParser.parseColumn();
                    alterColumn.setColumn(columnDef);

                    stmt.getItems().add(alterColumn);
                } else if (identifierEquals("CHANGE")) {
                    lexer.nextToken();
View Full Code Here

                                      + lexer.stringVal());
        }
    }

    public SQLColumnDefinition parseColumn() {
        SQLColumnDefinition column = createColumnDefinition();
        column.setName(name());
        column.setDataType(parseDataType());

        return parseColumnRest(column);
    }
View Full Code Here

        return parseColumnRest(column);
    }

    protected SQLColumnDefinition createColumnDefinition() {
        SQLColumnDefinition column = new SQLColumnDefinition();
        return column;
    }
View Full Code Here

            lexer.nextToken();

            for (;;) {
                if (lexer.token() == Token.IDENTIFIER //
                    || lexer.token() == Token.LITERAL_ALIAS) {
                    SQLColumnDefinition column = this.exprParser.parseColumn();
                    createTable.getTableElementList().add(column);
                } else if (lexer.token == Token.PRIMARY //
                           || lexer.token == Token.UNIQUE //
                           || lexer.token == Token.CHECK //
                           || lexer.token == Token.CONSTRAINT) {
                    SQLConstraint constraint = this.exprParser.parseConstaint();
                    constraint.setParent(createTable);
                    createTable.getTableElementList().add((SQLTableElement) constraint);
                } else if (lexer.token() == Token.TABLESPACE) {
                    throw new ParserException("TODO " + lexer.token());
                } else {
                    SQLColumnDefinition column = this.exprParser.parseColumn();
                    createTable.getTableElementList().add(column);
                }

                if (lexer.token() == Token.COMMA) {
                    lexer.nextToken();
View Full Code Here

TOP

Related Classes of com.alibaba.druid.sql.ast.statement.SQLColumnDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.