Search in sources :

Example 1 with OracleDataTypeTimestamp

use of com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeTimestamp in project druid by alibaba.

the class OracleExprParser method parseDataType.

public SQLDataType parseDataType() {
    if (lexer.token() == Token.CONSTRAINT || lexer.token() == Token.COMMA) {
        return null;
    }
    if (lexer.token() == Token.DEFAULT || lexer.token() == Token.NOT || lexer.token() == Token.NULL) {
        return null;
    }
    if (lexer.token() == Token.INTERVAL) {
        lexer.nextToken();
        if (identifierEquals("YEAR")) {
            lexer.nextToken();
            OracleDataTypeIntervalYear interval = new OracleDataTypeIntervalYear();
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                interval.addArgument(this.expr());
                accept(Token.RPAREN);
            }
            accept(Token.TO);
            acceptIdentifier("MONTH");
            return interval;
        } else {
            acceptIdentifier("DAY");
            OracleDataTypeIntervalDay interval = new OracleDataTypeIntervalDay();
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                interval.addArgument(this.expr());
                accept(Token.RPAREN);
            }
            accept(Token.TO);
            acceptIdentifier("SECOND");
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                interval.getFractionalSeconds().add(this.expr());
                accept(Token.RPAREN);
            }
            return interval;
        }
    }
    String typeName;
    if (identifierEquals("LONG")) {
        lexer.nextToken();
        acceptIdentifier("RAW");
        typeName = "LONG RAW";
    } else {
        SQLName typeExpr = name();
        typeName = typeExpr.toString();
    }
    if ("TIMESTAMP".equalsIgnoreCase(typeName)) {
        OracleDataTypeTimestamp timestamp = new OracleDataTypeTimestamp();
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            timestamp.addArgument(this.expr());
            accept(Token.RPAREN);
        }
        if (lexer.token() == Token.WITH) {
            lexer.nextToken();
            if (identifierEquals("LOCAL")) {
                lexer.nextToken();
                timestamp.setWithLocalTimeZone(true);
            } else {
                timestamp.setWithTimeZone(true);
            }
            acceptIdentifier("TIME");
            acceptIdentifier("ZONE");
        }
        return timestamp;
    }
    if (isCharType(typeName)) {
        SQLCharacterDataType charType = new SQLCharacterDataType(typeName);
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            charType.addArgument(this.expr());
            if (identifierEquals("CHAR")) {
                lexer.nextToken();
                charType.setCharType(SQLCharacterDataType.CHAR_TYPE_CHAR);
            } else if (identifierEquals("BYTE")) {
                lexer.nextToken();
                charType.setCharType(SQLCharacterDataType.CHAR_TYPE_BYTE);
            }
            accept(Token.RPAREN);
        }
        return parseCharTypeRest(charType);
    }
    if (lexer.token() == Token.PERCENT) {
        lexer.nextToken();
        if (identifierEquals("TYPE")) {
            lexer.nextToken();
            typeName += "%TYPE";
        } else if (identifierEquals("ROWTYPE")) {
            lexer.nextToken();
            typeName += "%ROWTYPE";
        } else {
            throw new ParserException("syntax error : " + lexer.token() + " " + lexer.stringVal());
        }
    }
    SQLDataType dataType = new SQLDataTypeImpl(typeName);
    return parseDataTypeRest(dataType);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) OracleDataTypeIntervalYear(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear) OracleDataTypeTimestamp(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeTimestamp) SQLDataType(com.alibaba.druid.sql.ast.SQLDataType) SQLCharacterDataType(com.alibaba.druid.sql.ast.statement.SQLCharacterDataType) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLDataTypeImpl(com.alibaba.druid.sql.ast.SQLDataTypeImpl) OracleDataTypeIntervalDay(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay)

Aggregations

SQLDataType (com.alibaba.druid.sql.ast.SQLDataType)1 SQLDataTypeImpl (com.alibaba.druid.sql.ast.SQLDataTypeImpl)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLCharacterDataType (com.alibaba.druid.sql.ast.statement.SQLCharacterDataType)1 OracleDataTypeIntervalDay (com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay)1 OracleDataTypeIntervalYear (com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear)1 OracleDataTypeTimestamp (com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeTimestamp)1 ParserException (com.alibaba.druid.sql.parser.ParserException)1