Search in sources :

Example 1 with OracleDataTypeIntervalYear

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

the class OracleExprParser method parseDataType.

public SQLDataType parseDataType(boolean restrict) {
    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 (lexer.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 (lexer.token() == Token.EXCEPTION) {
        typeName = "EXCEPTION";
        lexer.nextToken();
    } else if (lexer.identifierEquals(FnvHash.Constants.LONG)) {
        lexer.nextToken();
        if (lexer.identifierEquals(FnvHash.Constants.RAW)) {
            lexer.nextToken();
            typeName = "LONG RAW";
        } else {
            typeName = "LONG";
        }
    } else {
        SQLName typeExpr = name();
        typeName = typeExpr.toString();
    }
    if ("TIMESTAMP".equalsIgnoreCase(typeName)) {
        SQLDataTypeImpl timestamp = new SQLDataTypeImpl(typeName);
        timestamp.setDbType(dbType);
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            timestamp.addArgument(this.expr());
            accept(Token.RPAREN);
        }
        if (lexer.token() == Token.WITH) {
            lexer.nextToken();
            if (lexer.identifierEquals("LOCAL")) {
                lexer.nextToken();
                timestamp.setWithLocalTimeZone(true);
            }
            timestamp.setWithTimeZone(true);
            acceptIdentifier("TIME");
            acceptIdentifier("ZONE");
        }
        return timestamp;
    }
    if ("national".equalsIgnoreCase(typeName) && isCharType(lexer.hash_lower())) {
        typeName += ' ' + lexer.stringVal();
        lexer.nextToken();
        if (lexer.identifierEquals("VARYING")) {
            typeName += ' ' + lexer.stringVal();
            lexer.nextToken();
        }
        SQLCharacterDataType charType = new SQLCharacterDataType(typeName);
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            SQLExpr arg = this.expr();
            arg.setParent(charType);
            charType.addArgument(arg);
            accept(Token.RPAREN);
        }
        charType = (SQLCharacterDataType) parseCharTypeRest(charType);
        if (lexer.token() == Token.HINT) {
            List<SQLCommentHint> hints = this.parseHints();
            charType.setHints(hints);
        }
        return charType;
    }
    if (isCharType(typeName)) {
        if (lexer.identifierEquals("VARYING")) {
            typeName += ' ' + lexer.stringVal();
            lexer.nextToken();
        }
        SQLCharacterDataType charType = new SQLCharacterDataType(typeName);
        if (lexer.token() == Token.LPAREN) {
            lexer.nextToken();
            charType.addArgument(this.expr());
            if (lexer.identifierEquals("CHAR")) {
                lexer.nextToken();
                charType.setCharType(SQLCharacterDataType.CHAR_TYPE_CHAR);
            } else if (lexer.identifierEquals("BYTE")) {
                lexer.nextToken();
                charType.setCharType(SQLCharacterDataType.CHAR_TYPE_BYTE);
            }
            accept(Token.RPAREN);
        } else if (lexer.token() == Token.COMMA) {
            return parseCharTypeRest(charType);
        } else if (restrict) {
            accept(Token.LPAREN);
        }
        return parseCharTypeRest(charType);
    }
    if (lexer.token() == Token.PERCENT) {
        lexer.nextToken();
        if (lexer.identifierEquals("TYPE")) {
            lexer.nextToken();
            typeName += "%TYPE";
        } else if (lexer.identifierEquals("ROWTYPE")) {
            lexer.nextToken();
            typeName += "%ROWTYPE";
        } else {
            throw new ParserException("syntax error : " + lexer.info());
        }
    }
    SQLDataTypeImpl dataType = new SQLDataTypeImpl(typeName);
    dataType.setDbType(dbType);
    return parseDataTypeRest(dataType);
}
Also used : OracleDataTypeIntervalYear(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear) OracleDataTypeIntervalDay(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay)

Example 2 with OracleDataTypeIntervalYear

use of com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear 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)

Example 3 with OracleDataTypeIntervalYear

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

the class OracleASTVisitorAdapterTest method test_adapter.

public void test_adapter() throws Exception {
    OracleASTVisitorAdapter adapter = new OracleASTVisitorAdapter();
    new SQLScriptCommitStatement().accept(adapter);
    new OracleAnalytic().accept(adapter);
    new OracleAnalyticWindowing().accept(adapter);
    new SQLDateExpr().accept(adapter);
    new SQLDbLinkExpr().accept(adapter);
    new OracleSelectPivot.Item().accept(adapter);
    new OracleSelectPivot().accept(adapter);
    new CheckOption().accept(adapter);
    new ReadOnly().accept(adapter);
    new OracleSelectUnPivot().accept(adapter);
    new SQLTimestampExpr().accept(adapter);
    new PartitionExtensionClause().accept(adapter);
    new SQLGroupingSetExpr().accept(adapter);
    new OracleWithSubqueryEntry().accept(adapter);
    new OracleFileSpecification().accept(adapter);
    new OracleAlterTablespaceAddDataFile().accept(adapter);
    new OracleAlterTablespaceStatement().accept(adapter);
    new SQLCreateSequenceStatement().accept(adapter);
    new SQLLoopStatement().accept(adapter);
    new OracleIntervalExpr().accept(adapter);
    new OracleDeleteStatement().accept(adapter);
    new OracleUpdateStatement().accept(adapter);
    new SampleClause().accept(adapter);
    new OracleSelectTableReference().accept(adapter);
    new SearchClause().accept(adapter);
    new CycleClause().accept(adapter);
    new OracleBinaryFloatExpr().accept(adapter);
    new OracleBinaryDoubleExpr().accept(adapter);
    new OracleCursorExpr().accept(adapter);
    new OracleIsSetExpr().accept(adapter);
    new ReturnRowsClause().accept(adapter);
    new ModelClause().accept(adapter);
    new MainModelClause().accept(adapter);
    new ModelColumnClause().accept(adapter);
    new QueryPartitionClause().accept(adapter);
    new ModelColumn().accept(adapter);
    new ModelRulesClause().accept(adapter);
    new CellAssignmentItem().accept(adapter);
    new CellAssignment().accept(adapter);
    new SQLMergeStatement().accept(adapter);
    new MergeUpdateClause().accept(adapter);
    new MergeInsertClause().accept(adapter);
    new SQLErrorLoggingClause().accept(adapter);
    new OracleReturningClause().accept(adapter);
    new OracleInsertStatement().accept(adapter);
    new InsertIntoClause().accept(adapter);
    new OracleMultiInsertStatement().accept(adapter);
    new ConditionalInsertClause().accept(adapter);
    new ConditionalInsertClauseItem().accept(adapter);
    new OracleSelectQueryBlock().accept(adapter);
    new SQLBlockStatement().accept(adapter);
    new OracleLockTableStatement().accept(adapter);
    new OracleAlterSessionStatement().accept(adapter);
    new SQLExprStatement().accept(adapter);
    new OracleDatetimeExpr().accept(adapter);
    new OracleExceptionStatement().accept(adapter);
    new OracleExceptionStatement.Item().accept(adapter);
    new OracleArgumentExpr().accept(adapter);
    new OracleSetTransactionStatement().accept(adapter);
    new SQLDropSequenceStatement().accept(adapter);
    new OracleDataTypeIntervalDay().accept(adapter);
    new OracleDataTypeIntervalYear().accept(adapter);
    new OracleDropDbLinkStatement().accept(adapter);
    new OracleCreateDatabaseDbLinkStatement().accept(adapter);
    new SQLCreateProcedureStatement().accept(adapter);
    new SQLFetchStatement().accept(adapter);
    new OracleExitStatement().accept(adapter);
    new OracleExplainStatement().accept(adapter);
    new SQLAlterProcedureStatement().accept(adapter);
    new OracleAlterTableDropPartition().accept(adapter);
    new OracleAlterTableTruncatePartition().accept(adapter);
    new OracleAlterTableSplitPartition.TableSpaceItem().accept(adapter);
    new OracleAlterTableSplitPartition.UpdateIndexesClause().accept(adapter);
    new OracleAlterTableSplitPartition.NestedTablePartitionSpec().accept(adapter);
    new OracleAlterTableSplitPartition().accept(adapter);
    new OracleAlterTableModify().accept(adapter);
    new OracleCreateIndexStatement().accept(adapter);
    new SQLAlterIndexStatement().accept(adapter);
    new OracleForStatement().accept(adapter);
    new SQLAlterIndexStatement().accept(adapter);
    new OracleRangeExpr().accept(adapter);
    new OraclePrimaryKey().accept(adapter);
    new OracleCreateTableStatement().accept(adapter);
    new SQLAlterTableRename().accept(adapter);
    new OracleStorageClause().accept(adapter);
    new OracleGotoStatement().accept(adapter);
    new OracleLabelStatement().accept(adapter);
    new SQLParameter().accept(adapter);
    new SQLCommitStatement().accept(adapter);
    new OracleAlterTriggerStatement().accept(adapter);
    new OracleAlterSynonymStatement().accept(adapter);
    new OracleAlterViewStatement().accept(adapter);
    new OracleAlterTableMoveTablespace().accept(adapter);
    new SQLSizeExpr().accept(adapter);
}
Also used : ModelClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause) MergeUpdateClause(com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeUpdateClause) ConditionalInsertClauseItem(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.ConditionalInsertClauseItem) ReadOnly(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectRestriction.ReadOnly) OracleDataTypeIntervalYear(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear) SQLParameter(com.alibaba.druid.sql.ast.SQLParameter) InsertIntoClause(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.InsertIntoClause) ConditionalInsertClause(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.ConditionalInsertClause) CheckOption(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectRestriction.CheckOption) OracleASTVisitorAdapter(com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitorAdapter) OracleDataTypeIntervalDay(com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay) MergeInsertClause(com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeInsertClause)

Aggregations

OracleDataTypeIntervalDay (com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalDay)3 OracleDataTypeIntervalYear (com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeIntervalYear)3 SQLDataType (com.alibaba.druid.sql.ast.SQLDataType)1 SQLDataTypeImpl (com.alibaba.druid.sql.ast.SQLDataTypeImpl)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLParameter (com.alibaba.druid.sql.ast.SQLParameter)1 SQLCharacterDataType (com.alibaba.druid.sql.ast.statement.SQLCharacterDataType)1 MergeInsertClause (com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeInsertClause)1 MergeUpdateClause (com.alibaba.druid.sql.ast.statement.SQLMergeStatement.MergeUpdateClause)1 OracleDataTypeTimestamp (com.alibaba.druid.sql.dialect.oracle.ast.OracleDataTypeTimestamp)1 ModelClause (com.alibaba.druid.sql.dialect.oracle.ast.clause.ModelClause)1 ConditionalInsertClause (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.ConditionalInsertClause)1 ConditionalInsertClauseItem (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.ConditionalInsertClauseItem)1 InsertIntoClause (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleMultiInsertStatement.InsertIntoClause)1 CheckOption (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectRestriction.CheckOption)1 ReadOnly (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectRestriction.ReadOnly)1 OracleASTVisitorAdapter (com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitorAdapter)1 ParserException (com.alibaba.druid.sql.parser.ParserException)1