Search in sources :

Example 1 with SQLColumnReference

use of com.alibaba.druid.sql.ast.statement.SQLColumnReference in project druid by alibaba.

the class SQLExprParser method parseColumnRest.

public SQLColumnDefinition parseColumnRest(SQLColumnDefinition column) {
    if (lexer.token() == Token.DEFAULT) {
        lexer.nextToken();
        column.setDefaultExpr(bitOr());
        return parseColumnRest(column);
    }
    if (lexer.token() == Token.NOT) {
        lexer.nextToken();
        accept(Token.NULL);
        column.addConstraint(new SQLNotNullConstraint());
        return parseColumnRest(column);
    }
    if (lexer.token() == Token.NULL) {
        lexer.nextToken();
        column.getConstraints().add(new SQLNullConstraint());
        return parseColumnRest(column);
    }
    if (lexer.token == Token.PRIMARY) {
        lexer.nextToken();
        accept(Token.KEY);
        column.addConstraint(new SQLColumnPrimaryKey());
        return parseColumnRest(column);
    }
    if (lexer.token == Token.UNIQUE) {
        lexer.nextToken();
        if (lexer.token() == Token.KEY) {
            lexer.nextToken();
        }
        column.addConstraint(new SQLColumnUniqueKey());
        return parseColumnRest(column);
    }
    if (lexer.token == Token.CONSTRAINT) {
        lexer.nextToken();
        SQLName name = this.name();
        if (lexer.token() == Token.PRIMARY) {
            lexer.nextToken();
            accept(Token.KEY);
            SQLColumnPrimaryKey pk = new SQLColumnPrimaryKey();
            pk.setName(name);
            column.addConstraint(pk);
            return parseColumnRest(column);
        }
        if (lexer.token() == Token.UNIQUE) {
            lexer.nextToken();
            SQLColumnUniqueKey uk = new SQLColumnUniqueKey();
            uk.setName(name);
            column.addConstraint(uk);
            return parseColumnRest(column);
        }
        if (lexer.token() == Token.REFERENCES) {
            lexer.nextToken();
            SQLColumnReference ref = new SQLColumnReference();
            ref.setName(name);
            ref.setTable(this.name());
            accept(Token.LPAREN);
            this.names(ref.getColumns(), ref);
            accept(Token.RPAREN);
            column.addConstraint(ref);
            return parseColumnRest(column);
        }
        if (lexer.token() == Token.NOT) {
            lexer.nextToken();
            accept(Token.NULL);
            SQLNotNullConstraint notNull = new SQLNotNullConstraint();
            notNull.setName(name);
            column.addConstraint(notNull);
            return parseColumnRest(column);
        }
        if (lexer.token == Token.CHECK) {
            SQLColumnCheck check = parseColumnCheck();
            check.setName(name);
            check.setParent(column);
            column.addConstraint(check);
            return parseColumnRest(column);
        }
        if (lexer.token == Token.DEFAULT) {
            lexer.nextToken();
            SQLExpr expr = this.expr();
            column.setDefaultExpr(expr);
            return parseColumnRest(column);
        }
        throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
    }
    if (lexer.token == Token.CHECK) {
        SQLColumnCheck check = parseColumnCheck();
        column.addConstraint(check);
        return parseColumnRest(column);
    }
    if (lexer.token() == Token.COMMENT) {
        lexer.nextToken();
        column.setComment(primary());
        return parseColumnRest(column);
    }
    return column;
}
Also used : SQLNotNullConstraint(com.alibaba.druid.sql.ast.statement.SQLNotNullConstraint) SQLColumnPrimaryKey(com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey) SQLColumnReference(com.alibaba.druid.sql.ast.statement.SQLColumnReference) SQLColumnCheck(com.alibaba.druid.sql.ast.statement.SQLColumnCheck) SQLColumnUniqueKey(com.alibaba.druid.sql.ast.statement.SQLColumnUniqueKey) SQLNullConstraint(com.alibaba.druid.sql.ast.statement.SQLNullConstraint)

Aggregations

SQLColumnCheck (com.alibaba.druid.sql.ast.statement.SQLColumnCheck)1 SQLColumnPrimaryKey (com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey)1 SQLColumnReference (com.alibaba.druid.sql.ast.statement.SQLColumnReference)1 SQLColumnUniqueKey (com.alibaba.druid.sql.ast.statement.SQLColumnUniqueKey)1 SQLNotNullConstraint (com.alibaba.druid.sql.ast.statement.SQLNotNullConstraint)1 SQLNullConstraint (com.alibaba.druid.sql.ast.statement.SQLNullConstraint)1