Search in sources :

Example 21 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class OracleSelectParser method parseTableSource.

@Override
public SQLTableSource parseTableSource() {
    if (lexer.token() == (Token.LPAREN)) {
        lexer.nextToken();
        OracleSelectSubqueryTableSource tableSource;
        if (lexer.token() == Token.SELECT || lexer.token() == Token.WITH) {
            tableSource = new OracleSelectSubqueryTableSource(select());
        } else if (lexer.token() == (Token.LPAREN)) {
            tableSource = new OracleSelectSubqueryTableSource(select());
        } else {
            throw new ParserException("TODO :" + lexer.token());
        }
        accept(Token.RPAREN);
        parsePivot((OracleSelectTableSource) tableSource);
        return parseTableSourceRest(tableSource);
    }
    if (lexer.token() == (Token.SELECT)) {
        throw new ParserException("TODO");
    }
    OracleSelectTableReference tableReference = new OracleSelectTableReference();
    if (identifierEquals("ONLY")) {
        lexer.nextToken();
        tableReference.setOnly(true);
        accept(Token.LPAREN);
        parseTableSourceQueryTableExpr(tableReference);
        accept(Token.RPAREN);
    } else {
        parseTableSourceQueryTableExpr(tableReference);
        parsePivot(tableReference);
    }
    return parseTableSourceRest(tableReference);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) OracleSelectTableReference(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectTableReference) OracleSelectSubqueryTableSource(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectSubqueryTableSource)

Example 22 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class OracleStatementParser method parseAlterTable.

private SQLStatement parseAlterTable() {
    lexer.nextToken();
    SQLAlterTableStatement stmt = new SQLAlterTableStatement(getDbType());
    stmt.setName(this.exprParser.name());
    for (; ; ) {
        if (identifierEquals("ADD")) {
            lexer.nextToken();
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                SQLAlterTableAddColumn item = parseAlterTableAddColumn();
                stmt.addItem(item);
                accept(Token.RPAREN);
            } else if (lexer.token() == Token.CONSTRAINT) {
                OracleConstraint constraint = ((OracleExprParser) this.exprParser).parseConstaint();
                SQLAlterTableAddConstraint item = new SQLAlterTableAddConstraint();
                constraint.setParent(item);
                item.setParent(stmt);
                item.setConstraint(constraint);
                stmt.addItem(item);
            } else if (lexer.token() == Token.IDENTIFIER) {
                SQLAlterTableAddColumn item = parseAlterTableAddColumn();
                stmt.addItem(item);
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
            continue;
        } else if (identifierEquals("MOVE")) {
            lexer.nextToken();
            if (lexer.token() == Token.TABLESPACE) {
                lexer.nextToken();
                OracleAlterTableMoveTablespace item = new OracleAlterTableMoveTablespace();
                item.setName(this.exprParser.name());
                stmt.addItem(item);
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
        } else if (identifierEquals("RENAME")) {
            stmt.addItem(parseAlterTableRename());
        } else if (identifierEquals("MODIFY")) {
            lexer.nextToken();
            OracleAlterTableModify item = new OracleAlterTableModify();
            if (lexer.token() == Token.LPAREN) {
                lexer.nextToken();
                for (; ; ) {
                    SQLColumnDefinition columnDef = this.exprParser.parseColumn();
                    item.addColumn(columnDef);
                    if (lexer.token() == Token.COMMA) {
                        lexer.nextToken();
                        continue;
                    }
                    break;
                }
                accept(Token.RPAREN);
            } else {
                SQLColumnDefinition columnDef = this.exprParser.parseColumn();
                item.addColumn(columnDef);
            }
            stmt.addItem(item);
            continue;
        } else if (identifierEquals("SPLIT")) {
            parseAlterTableSplit(stmt);
            continue;
        } else if (lexer.token() == Token.TRUNCATE) {
            lexer.nextToken();
            if (identifierEquals("PARTITION")) {
                lexer.nextToken();
                OracleAlterTableTruncatePartition item = new OracleAlterTableTruncatePartition();
                item.setName(this.exprParser.name());
                stmt.addItem(item);
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
            continue;
        } else if (lexer.token() == Token.DROP) {
            parseAlterDrop(stmt);
            continue;
        } else if (lexer.token() == Token.DISABLE) {
            lexer.nextToken();
            if (lexer.token() == Token.CONSTRAINT) {
                lexer.nextToken();
                SQLAlterTableEnableConstraint item = new SQLAlterTableEnableConstraint();
                item.setConstraintName(this.exprParser.name());
                stmt.addItem(item);
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
        } else if (lexer.token() == Token.ENABLE) {
            lexer.nextToken();
            if (lexer.token() == Token.CONSTRAINT) {
                lexer.nextToken();
                SQLAlterTableDisableConstraint item = new SQLAlterTableDisableConstraint();
                item.setConstraintName(this.exprParser.name());
                stmt.addItem(item);
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
        }
        break;
    }
    if (lexer.token() == Token.UPDATE) {
        lexer.nextToken();
        if (identifierEquals("GLOBAL")) {
            lexer.nextToken();
            acceptIdentifier("INDEXES");
            stmt.setUpdateGlobalIndexes(true);
        } else {
            throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
        }
    }
    return stmt;
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) OracleAlterTableMoveTablespace(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableMoveTablespace) OracleAlterTableModify(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableModify) OracleConstraint(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint) OracleAlterTableTruncatePartition(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTableTruncatePartition)

Example 23 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class OracleStatementParser method parserAlter.

public SQLStatement parserAlter() {
    accept(Token.ALTER);
    if (lexer.token() == Token.SESSION) {
        lexer.nextToken();
        OracleAlterSessionStatement stmt = new OracleAlterSessionStatement();
        if (lexer.token() == Token.SET) {
            lexer.nextToken();
            parseAssignItems(stmt.getItems(), stmt);
        } else {
            throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
        }
        return stmt;
    } else if (lexer.token() == Token.PROCEDURE) {
        lexer.nextToken();
        OracleAlterProcedureStatement stmt = new OracleAlterProcedureStatement();
        stmt.setName(this.exprParser.name());
        if (identifierEquals("COMPILE")) {
            lexer.nextToken();
            stmt.setCompile(true);
        }
        if (identifierEquals("REUSE")) {
            lexer.nextToken();
            acceptIdentifier("SETTINGS");
            stmt.setReuseSettings(true);
        }
        return stmt;
    } else if (lexer.token() == Token.TABLE) {
        return parseAlterTable();
    } else if (lexer.token() == Token.INDEX) {
        lexer.nextToken();
        OracleAlterIndexStatement stmt = new OracleAlterIndexStatement();
        stmt.setName(this.exprParser.name());
        if (identifierEquals("RENAME")) {
            lexer.nextToken();
            accept(Token.TO);
            stmt.setRenameTo(this.exprParser.name());
        }
        for (; ; ) {
            if (identifierEquals("rebuild")) {
                lexer.nextToken();
                OracleAlterIndexStatement.Rebuild rebuild = new OracleAlterIndexStatement.Rebuild();
                stmt.setRebuild(rebuild);
                continue;
            } else if (identifierEquals("MONITORING")) {
                lexer.nextToken();
                acceptIdentifier("USAGE");
                stmt.setMonitoringUsage(Boolean.TRUE);
                continue;
            } else if (identifierEquals("PARALLEL")) {
                lexer.nextToken();
                stmt.setParallel(this.exprParser.expr());
            }
            break;
        }
        return stmt;
    } else if (lexer.token() == Token.TRIGGER) {
        lexer.nextToken();
        OracleAlterTriggerStatement stmt = new OracleAlterTriggerStatement();
        stmt.setName(this.exprParser.name());
        for (; ; ) {
            if (lexer.token() == Token.ENABLE) {
                lexer.nextToken();
                stmt.setEnable(Boolean.TRUE);
                continue;
            } else if (lexer.token() == Token.DISABLE) {
                lexer.nextToken();
                stmt.setEnable(Boolean.FALSE);
                continue;
            } else if (identifierEquals("COMPILE")) {
                lexer.nextToken();
                stmt.setCompile(true);
                continue;
            }
            break;
        }
        return stmt;
    } else if (identifierEquals("SYNONYM")) {
        lexer.nextToken();
        OracleAlterSynonymStatement stmt = new OracleAlterSynonymStatement();
        stmt.setName(this.exprParser.name());
        for (; ; ) {
            if (lexer.token() == Token.ENABLE) {
                lexer.nextToken();
                stmt.setEnable(Boolean.TRUE);
                continue;
            } else if (lexer.token() == Token.DISABLE) {
                lexer.nextToken();
                stmt.setEnable(Boolean.FALSE);
                continue;
            } else if (identifierEquals("COMPILE")) {
                lexer.nextToken();
                stmt.setCompile(true);
                continue;
            }
            break;
        }
        return stmt;
    } else if (lexer.token() == Token.VIEW) {
        lexer.nextToken();
        OracleAlterViewStatement stmt = new OracleAlterViewStatement();
        stmt.setName(this.exprParser.name());
        for (; ; ) {
            if (lexer.token() == Token.ENABLE) {
                lexer.nextToken();
                stmt.setEnable(Boolean.TRUE);
                continue;
            } else if (lexer.token() == Token.DISABLE) {
                lexer.nextToken();
                stmt.setEnable(Boolean.FALSE);
                continue;
            } else if (identifierEquals("COMPILE")) {
                lexer.nextToken();
                stmt.setCompile(true);
                continue;
            }
            break;
        }
        return stmt;
    } else if (lexer.token() == Token.TABLESPACE) {
        lexer.nextToken();
        OracleAlterTablespaceStatement stmt = new OracleAlterTablespaceStatement();
        stmt.setName(this.exprParser.name());
        if (identifierEquals("ADD")) {
            lexer.nextToken();
            if (identifierEquals("DATAFILE")) {
                lexer.nextToken();
                OracleAlterTablespaceAddDataFile item = new OracleAlterTablespaceAddDataFile();
                for (; ; ) {
                    OracleFileSpecification file = new OracleFileSpecification();
                    for (; ; ) {
                        SQLExpr fileName = this.exprParser.expr();
                        file.getFileNames().add(fileName);
                        if (lexer.token() == Token.COMMA) {
                            lexer.nextToken();
                            continue;
                        }
                        break;
                    }
                    if (identifierEquals("SIZE")) {
                        lexer.nextToken();
                        file.setSize(this.exprParser.expr());
                    }
                    if (identifierEquals("AUTOEXTEND")) {
                        lexer.nextToken();
                        if (identifierEquals("OFF")) {
                            lexer.nextToken();
                            file.setAutoExtendOff(true);
                        } else if (identifierEquals("ON")) {
                            lexer.nextToken();
                            file.setAutoExtendOn(this.exprParser.expr());
                        } else {
                            throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
                        }
                    }
                    item.getFiles().add(file);
                    if (lexer.token() == Token.COMMA) {
                        lexer.nextToken();
                        continue;
                    }
                    break;
                }
                stmt.setItem(item);
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
        } else {
            throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
        }
        return stmt;
    }
    throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) OracleAlterProcedureStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterProcedureStatement) OracleAlterTablespaceAddDataFile(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTablespaceAddDataFile) OracleAlterSessionStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterSessionStatement) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) OracleAlterSynonymStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterSynonymStatement) OracleAlterIndexStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterIndexStatement) OracleAlterTriggerStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTriggerStatement) OracleAlterTablespaceStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterTablespaceStatement) OracleAlterViewStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleAlterViewStatement) OracleFileSpecification(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleFileSpecification)

Example 24 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class OracleCreateTableParser method subPartitionBy.

protected SQLSubPartitionBy subPartitionBy() {
    lexer.nextToken();
    accept(Token.BY);
    if (identifierEquals("HASH")) {
        lexer.nextToken();
        accept(Token.LPAREN);
        SQLSubPartitionByHash byHash = new SQLSubPartitionByHash();
        SQLExpr expr = this.exprParser.expr();
        byHash.setExpr(expr);
        accept(Token.RPAREN);
        return byHash;
    } else if (identifierEquals("LIST")) {
        lexer.nextToken();
        accept(Token.LPAREN);
        SQLSubPartitionByList byList = new SQLSubPartitionByList();
        SQLName column = this.exprParser.name();
        byList.setColumn(column);
        accept(Token.RPAREN);
        if (identifierEquals("SUBPARTITION")) {
            lexer.nextToken();
            acceptIdentifier("TEMPLATE");
            accept(Token.LPAREN);
            for (; ; ) {
                SQLSubPartition subPartition = parseSubPartition();
                subPartition.setParent(byList);
                byList.getSubPartitionTemplate().add(subPartition);
                if (lexer.token() == Token.COMMA) {
                    lexer.nextToken();
                    continue;
                }
                break;
            }
            accept(Token.RPAREN);
        }
        return byList;
    }
    throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
}
Also used : SQLSubPartitionByList(com.alibaba.druid.sql.ast.SQLSubPartitionByList) ParserException(com.alibaba.druid.sql.parser.ParserException) SQLSubPartition(com.alibaba.druid.sql.ast.SQLSubPartition) SQLSubPartitionByHash(com.alibaba.druid.sql.ast.SQLSubPartitionByHash) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 25 with ParserException

use of com.alibaba.druid.sql.parser.ParserException in project druid by alibaba.

the class OracleCreateTableParser method parseCrateTable.

public OracleCreateTableStatement parseCrateTable(boolean acceptCreate) {
    OracleCreateTableStatement stmt = (OracleCreateTableStatement) super.parseCrateTable(acceptCreate);
    for (; ; ) {
        if (lexer.token() == Token.TABLESPACE) {
            lexer.nextToken();
            stmt.setTablespace(this.exprParser.name());
            continue;
        } else if (identifierEquals("IN_MEMORY_METADATA")) {
            lexer.nextToken();
            stmt.setInMemoryMetadata(true);
            continue;
        } else if (identifierEquals("CURSOR_SPECIFIC_SEGMENT")) {
            lexer.nextToken();
            stmt.setCursorSpecificSegment(true);
            continue;
        } else if (identifierEquals("NOPARALLEL")) {
            lexer.nextToken();
            stmt.setParallel(false);
            continue;
        } else if (lexer.token() == Token.LOGGING) {
            lexer.nextToken();
            stmt.setLogging(Boolean.TRUE);
            continue;
        } else if (lexer.token() == Token.CACHE) {
            lexer.nextToken();
            stmt.setCache(Boolean.TRUE);
            continue;
        } else if (lexer.token() == Token.NOCACHE) {
            lexer.nextToken();
            stmt.setCache(Boolean.FALSE);
            continue;
        } else if (lexer.token() == Token.NOCOMPRESS) {
            lexer.nextToken();
            stmt.setCompress(Boolean.FALSE);
            continue;
        } else if (lexer.token() == Token.ON) {
            lexer.nextToken();
            accept(Token.COMMIT);
            stmt.setOnCommit(true);
            continue;
        } else if (identifierEquals("PRESERVE")) {
            lexer.nextToken();
            acceptIdentifier("ROWS");
            stmt.setPreserveRows(true);
            continue;
        } else if (identifierEquals("STORAGE")) {
            OracleStorageClause storage = ((OracleExprParser) this.exprParser).parseStorage();
            stmt.setStorage(storage);
            continue;
        } else if (identifierEquals("organization")) {
            lexer.nextToken();
            accept(Token.INDEX);
            stmt.setOrganizationIndex(true);
            continue;
        } else if (lexer.token() == Token.PCTFREE) {
            lexer.nextToken();
            stmt.setPtcfree(this.exprParser.expr());
            continue;
        } else if (identifierEquals("PCTUSED")) {
            lexer.nextToken();
            stmt.setPctused(this.exprParser.expr());
            continue;
        } else if (lexer.token() == Token.STORAGE) {
            OracleStorageClause storage = ((OracleExprParser) this.exprParser).parseStorage();
            stmt.setStorage(storage);
            continue;
        } else if (lexer.token() == Token.LOB) {
            OracleLobStorageClause lobStorage = ((OracleExprParser) this.exprParser).parseLobStorage();
            stmt.setLobStorage(lobStorage);
            continue;
        } else if (lexer.token() == Token.INITRANS) {
            lexer.nextToken();
            stmt.setInitrans(this.exprParser.expr());
            continue;
        } else if (lexer.token() == Token.MAXTRANS) {
            lexer.nextToken();
            stmt.setMaxtrans(this.exprParser.expr());
            continue;
        } else if (lexer.token() == Token.SEGMENT) {
            lexer.nextToken();
            accept(Token.CREATION);
            if (lexer.token() == Token.IMMEDIATE) {
                lexer.nextToken();
                stmt.setDeferredSegmentCreation(DeferredSegmentCreation.IMMEDIATE);
            } else {
                accept(Token.DEFERRED);
                stmt.setDeferredSegmentCreation(DeferredSegmentCreation.DEFERRED);
            }
            continue;
        } else if (identifierEquals("PARTITION")) {
            lexer.nextToken();
            accept(Token.BY);
            if (identifierEquals("RANGE")) {
                SQLPartitionByRange partitionByRange = partitionByRange();
                partitionClauseRest(partitionByRange);
                stmt.setPartitioning(partitionByRange);
                continue;
            } else if (identifierEquals("HASH")) {
                SQLPartitionByHash partitionByHash = partitionByHash();
                partitionClauseRest(partitionByHash);
                stmt.setPartitioning(partitionByHash);
                continue;
            } else if (identifierEquals("LIST")) {
                SQLPartitionByList partitionByList = partitionByList();
                partitionClauseRest(partitionByList);
                stmt.setPartitioning(partitionByList);
                continue;
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
        }
        break;
    }
    if (lexer.token() == Token.AS) {
        lexer.nextToken();
        OracleSelect select = new OracleSelectParser(exprParser).select();
        stmt.setSelect(select);
    }
    return stmt;
}
Also used : OracleLobStorageClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.OracleLobStorageClause) ParserException(com.alibaba.druid.sql.parser.ParserException) OracleSelect(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelect) OracleStorageClause(com.alibaba.druid.sql.dialect.oracle.ast.clause.OracleStorageClause) SQLPartitionByRange(com.alibaba.druid.sql.ast.SQLPartitionByRange) SQLPartitionByHash(com.alibaba.druid.sql.ast.SQLPartitionByHash) OracleCreateTableStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCreateTableStatement) SQLPartitionByList(com.alibaba.druid.sql.ast.SQLPartitionByList)

Aggregations

ParserException (com.alibaba.druid.sql.parser.ParserException)98 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)25 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)18 SQLName (com.alibaba.druid.sql.ast.SQLName)16 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)12 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)10 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)9 Token (com.alibaba.druid.sql.parser.Token)9 SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)5 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)5 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)5 SQLSelect (com.alibaba.druid.sql.ast.statement.SQLSelect)5 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)4 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)4 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)4 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)4 OracleConstraint (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint)4 DbType (com.alibaba.druid.DbType)3 SQLDeclareItem (com.alibaba.druid.sql.ast.SQLDeclareItem)3 SQLPartitionByHash (com.alibaba.druid.sql.ast.SQLPartitionByHash)3