Search in sources :

Example 1 with OracleGotoStatement

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

the class OracleStatementParser method parseStatementList.

public void parseStatementList(List<SQLStatement> statementList, int max) {
    for (; ; ) {
        if (max != -1) {
            if (statementList.size() >= max) {
                return;
            }
        }
        if (lexer.token() == Token.EOF) {
            return;
        }
        if (lexer.token() == Token.END) {
            return;
        }
        if (lexer.token() == Token.ELSE) {
            return;
        }
        if (lexer.token() == (Token.SEMI)) {
            lexer.nextToken();
            continue;
        }
        if (lexer.token() == (Token.SELECT)) {
            SQLSelectStatement stmt = new SQLSelectStatement(new OracleSelectParser(this.exprParser).select(), JdbcConstants.ORACLE);
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == (Token.UPDATE)) {
            statementList.add(parseUpdateStatement());
            continue;
        }
        if (lexer.token() == (Token.CREATE)) {
            statementList.add(parseCreate());
            continue;
        }
        if (lexer.token() == Token.INSERT) {
            statementList.add(parseInsert());
            continue;
        }
        if (lexer.token() == (Token.DELETE)) {
            statementList.add(parseDeleteStatement());
            continue;
        }
        if (lexer.token() == (Token.SLASH)) {
            lexer.nextToken();
            statementList.add(new OraclePLSQLCommitStatement());
            continue;
        }
        if (lexer.token() == Token.ALTER) {
            statementList.add(parserAlter());
            continue;
        }
        if (lexer.token() == Token.WITH) {
            statementList.add(new SQLSelectStatement(new OracleSelectParser(this.exprParser).select()));
            continue;
        }
        if (lexer.token() == Token.LBRACE || identifierEquals("CALL")) {
            statementList.add(this.parseCall());
            continue;
        }
        if (lexer.token() == Token.MERGE) {
            statementList.add(this.parseMerge());
            continue;
        }
        if (lexer.token() == Token.BEGIN) {
            statementList.add(this.parseBlock());
            continue;
        }
        if (lexer.token() == Token.DECLARE) {
            statementList.add(this.parseBlock());
            continue;
        }
        if (lexer.token() == Token.LOCK) {
            statementList.add(this.parseLock());
            continue;
        }
        if (lexer.token() == Token.TRUNCATE) {
            statementList.add(this.parseTruncate());
            continue;
        }
        if (lexer.token() == Token.VARIANT) {
            SQLExpr variant = this.exprParser.primary();
            if (variant instanceof SQLBinaryOpExpr) {
                SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) variant;
                if (binaryOpExpr.getOperator() == SQLBinaryOperator.Assignment) {
                    SQLSetStatement stmt = new SQLSetStatement(binaryOpExpr.getLeft(), binaryOpExpr.getRight(), getDbType());
                    statementList.add(stmt);
                    continue;
                }
            }
            accept(Token.COLONEQ);
            SQLExpr value = this.exprParser.expr();
            SQLSetStatement stmt = new SQLSetStatement(variant, value, getDbType());
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == Token.EXCEPTION) {
            statementList.add(this.parseException());
            continue;
        }
        if (identifierEquals("EXIT")) {
            lexer.nextToken();
            OracleExitStatement stmt = new OracleExitStatement();
            if (lexer.token() == Token.WHEN) {
                lexer.nextToken();
                stmt.setWhen(this.exprParser.expr());
            }
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == Token.FETCH || identifierEquals("FETCH")) {
            SQLStatement stmt = parseFetch();
            statementList.add(stmt);
            continue;
        }
        if (identifierEquals("ROLLBACK")) {
            SQLRollbackStatement stmt = parseRollback();
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == Token.EXPLAIN) {
            statementList.add(this.parseExplain());
            continue;
        }
        if (lexer.token() == Token.IDENTIFIER) {
            SQLExpr expr = exprParser.expr();
            OracleExprStatement stmt = new OracleExprStatement(expr);
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == Token.LPAREN) {
            char ch = lexer.current();
            int bp = lexer.bp();
            lexer.nextToken();
            if (lexer.token() == Token.SELECT) {
                lexer.reset(bp, ch, Token.LPAREN);
                statementList.add(this.parseSelect());
                continue;
            } else {
                throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
            }
        }
        if (lexer.token() == Token.SET) {
            statementList.add(this.parseSet());
            continue;
        }
        if (lexer.token() == Token.GRANT) {
            statementList.add(this.parseGrant());
            continue;
        }
        if (lexer.token() == Token.REVOKE) {
            statementList.add(this.parseRevoke());
            continue;
        }
        if (lexer.token() == Token.COMMENT) {
            statementList.add(this.parseComment());
            continue;
        }
        if (lexer.token() == Token.FOR) {
            statementList.add(this.parseFor());
            continue;
        }
        if (lexer.token() == Token.LOOP) {
            statementList.add(this.parseLoop());
            continue;
        }
        if (lexer.token() == Token.IF) {
            statementList.add(this.parseIf());
            continue;
        }
        if (lexer.token() == Token.GOTO) {
            lexer.nextToken();
            SQLName label = this.exprParser.name();
            OracleGotoStatement stmt = new OracleGotoStatement(label);
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == Token.COMMIT) {
            lexer.nextToken();
            if (identifierEquals("WORK")) {
                lexer.nextToken();
            }
            OracleCommitStatement stmt = new OracleCommitStatement();
            if (identifierEquals("WRITE")) {
                stmt.setWrite(true);
                lexer.nextToken();
                for (; ; ) {
                    if (lexer.token() == Token.WAIT) {
                        lexer.nextToken();
                        stmt.setWait(Boolean.TRUE);
                        continue;
                    } else if (lexer.token() == Token.NOWAIT) {
                        lexer.nextToken();
                        stmt.setWait(Boolean.FALSE);
                        continue;
                    } else if (lexer.token() == Token.IMMEDIATE) {
                        lexer.nextToken();
                        stmt.setImmediate(Boolean.TRUE);
                        continue;
                    } else if (identifierEquals("BATCH")) {
                        lexer.nextToken();
                        stmt.setImmediate(Boolean.FALSE);
                        continue;
                    }
                    break;
                }
            }
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == Token.SAVEPOINT) {
            lexer.nextToken();
            OracleSavePointStatement stmt = new OracleSavePointStatement();
            if (lexer.token() == Token.TO) {
                lexer.nextToken();
                stmt.setTo(this.exprParser.name());
            }
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == Token.LTLT) {
            lexer.nextToken();
            SQLName label = this.exprParser.name();
            OracleLabelStatement stmt = new OracleLabelStatement(label);
            accept(Token.GTGT);
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == Token.DROP) {
            lexer.nextToken();
            if (lexer.token() == Token.TABLE) {
                SQLDropTableStatement stmt = parseDropTable(false);
                statementList.add(stmt);
                continue;
            }
            boolean isPublic = false;
            if (identifierEquals("PUBLIC")) {
                lexer.nextToken();
                isPublic = true;
            }
            if (lexer.token() == Token.DATABASE) {
                lexer.nextToken();
                if (identifierEquals("LINK")) {
                    lexer.nextToken();
                    OracleDropDbLinkStatement stmt = new OracleDropDbLinkStatement();
                    if (isPublic) {
                        stmt.setPublic(isPublic);
                    }
                    stmt.setName(this.exprParser.name());
                    statementList.add(stmt);
                    continue;
                }
            }
            if (lexer.token() == Token.INDEX) {
                SQLStatement stmt = parseDropIndex();
                statementList.add(stmt);
                continue;
            }
            if (lexer.token() == Token.VIEW) {
                SQLStatement stmt = parseDropView(false);
                statementList.add(stmt);
                continue;
            }
            if (lexer.token() == Token.SEQUENCE) {
                SQLDropSequenceStatement stmt = parseDropSequece(false);
                statementList.add(stmt);
                continue;
            }
            if (lexer.token() == Token.TRIGGER) {
                SQLDropTriggerStatement stmt = parseDropTrigger(false);
                statementList.add(stmt);
                continue;
            }
            if (lexer.token() == Token.USER) {
                SQLDropUserStatement stmt = parseDropUser();
                statementList.add(stmt);
                continue;
            }
            if (lexer.token() == Token.PROCEDURE) {
                SQLDropProcedureStatement stmt = parseDropProcedure(false);
                statementList.add(stmt);
                continue;
            }
            throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
        }
        if (lexer.token() == Token.NULL) {
            lexer.nextToken();
            OracleExprStatement stmt = new OracleExprStatement(new SQLNullExpr());
            statementList.add(stmt);
            continue;
        }
        if (lexer.token() == Token.OPEN) {
            SQLStatement stmt = this.parseOpen();
            statementList.add(stmt);
            continue;
        }
        throw new ParserException("TODO : " + lexer.token() + " " + lexer.stringVal());
    }
}
Also used : OracleExitStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExitStatement) OracleDropDbLinkStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDropDbLinkStatement) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) OracleCommitStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCommitStatement) OracleSavePointStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSavePointStatement) OracleExprStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExprStatement) OracleLabelStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleLabelStatement) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) OraclePLSQLCommitStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OraclePLSQLCommitStatement) ParserException(com.alibaba.druid.sql.parser.ParserException) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLHint(com.alibaba.druid.sql.ast.SQLHint) OracleConstraint(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint) OracleGotoStatement(com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGotoStatement)

Aggregations

SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLHint (com.alibaba.druid.sql.ast.SQLHint)1 SQLName (com.alibaba.druid.sql.ast.SQLName)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)1 SQLNullExpr (com.alibaba.druid.sql.ast.expr.SQLNullExpr)1 OracleCommitStatement (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleCommitStatement)1 OracleConstraint (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleConstraint)1 OracleDropDbLinkStatement (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleDropDbLinkStatement)1 OracleExitStatement (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExitStatement)1 OracleExprStatement (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleExprStatement)1 OracleGotoStatement (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleGotoStatement)1 OracleLabelStatement (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleLabelStatement)1 OraclePLSQLCommitStatement (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OraclePLSQLCommitStatement)1 OracleSavePointStatement (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSavePointStatement)1 ParserException (com.alibaba.druid.sql.parser.ParserException)1