Search in sources :

Example 21 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class MySqlExprParser method parseAggregateExprRest.

protected SQLAggregateExpr parseAggregateExprRest(SQLAggregateExpr aggregateExpr) {
    if (lexer.token() == Token.ORDER) {
        SQLOrderBy orderBy = this.parseOrderBy();
        aggregateExpr.putAttribute("ORDER BY", orderBy);
    }
    if (identifierEquals("SEPARATOR")) {
        lexer.nextToken();
        SQLExpr seperator = this.primary();
        aggregateExpr.putAttribute("SEPARATOR", seperator);
    }
    return aggregateExpr;
}
Also used : SQLOrderBy(com.alibaba.druid.sql.ast.SQLOrderBy) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 22 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class DB2SelectParser method query.

@Override
public SQLSelectQuery query() {
    if (lexer.token() == Token.LPAREN) {
        lexer.nextToken();
        SQLSelectQuery select = query();
        accept(Token.RPAREN);
        return queryRest(select);
    }
    accept(Token.SELECT);
    if (lexer.token() == Token.COMMENT) {
        lexer.nextToken();
    }
    DB2SelectQueryBlock queryBlock = new DB2SelectQueryBlock();
    if (lexer.token() == Token.DISTINCT) {
        queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
        lexer.nextToken();
    } else if (lexer.token() == Token.UNIQUE) {
        queryBlock.setDistionOption(SQLSetQuantifier.UNIQUE);
        lexer.nextToken();
    } else if (lexer.token() == Token.ALL) {
        queryBlock.setDistionOption(SQLSetQuantifier.ALL);
        lexer.nextToken();
    }
    parseSelectList(queryBlock);
    parseFrom(queryBlock);
    parseWhere(queryBlock);
    parseGroupBy(queryBlock);
    if (lexer.token() == Token.ORDER) {
        SQLOrderBy orderBy = parseOrderBy();
        queryBlock.setOrderBy(orderBy);
    }
    for (; ; ) {
        if (lexer.token() == Token.FETCH) {
            lexer.nextToken();
            accept(Token.FIRST);
            SQLExpr first = this.exprParser.primary();
            queryBlock.setFirst(first);
            if (identifierEquals("ROW") || identifierEquals("ROWS")) {
                lexer.nextToken();
            }
            accept(Token.ONLY);
            continue;
        }
        if (lexer.token() == Token.WITH) {
            lexer.nextToken();
            if (identifierEquals("RR")) {
                queryBlock.setIsolation(Isolation.RR);
            } else if (identifierEquals("RS")) {
                queryBlock.setIsolation(Isolation.RS);
            } else if (identifierEquals("CS")) {
                queryBlock.setIsolation(Isolation.CS);
            } else if (identifierEquals("UR")) {
                queryBlock.setIsolation(Isolation.UR);
            } else {
                throw new ParserException("TODO");
            }
            lexer.nextToken();
            continue;
        }
        if (lexer.token() == Token.FOR) {
            lexer.nextToken();
            if (lexer.token() == Token.UPDATE) {
                queryBlock.setForUpdate(true);
                lexer.nextToken();
            } else {
                acceptIdentifier("READ");
                accept(Token.ONLY);
                queryBlock.setForReadOnly(true);
            }
        }
        if (lexer.token() == Token.OPTIMIZE) {
            lexer.nextToken();
            accept(Token.FOR);
            queryBlock.setOptimizeFor(this.expr());
            if (identifierEquals("ROW")) {
                lexer.nextToken();
            } else {
                acceptIdentifier("ROWS");
            }
        }
        break;
    }
    return queryRest(queryBlock);
}
Also used : ParserException(com.alibaba.druid.sql.parser.ParserException) SQLOrderBy(com.alibaba.druid.sql.ast.SQLOrderBy) SQLSelectQuery(com.alibaba.druid.sql.ast.statement.SQLSelectQuery) DB2SelectQueryBlock(com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 23 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr in project druid by alibaba.

the class OracleSelectParser method parseInto.

protected void parseInto(OracleSelectQueryBlock x) {
    if (lexer.token() == Token.INTO) {
        lexer.nextToken();
        SQLExpr expr = expr();
        if (lexer.token() != Token.COMMA) {
            x.setInto(expr);
            return;
        }
        SQLListExpr list = new SQLListExpr();
        list.addItem(expr);
        while (lexer.token() == Token.COMMA) {
            lexer.nextToken();
            list.addItem(expr());
        }
        x.setInto(list);
    }
}
Also used : SQLListExpr(com.alibaba.druid.sql.ast.expr.SQLListExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 24 with SQLExpr

use of com.alibaba.druid.sql.ast.SQLExpr 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 25 with SQLExpr

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

Aggregations

SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)422 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)71 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)68 SQLName (com.alibaba.druid.sql.ast.SQLName)47 SQLIntegerExpr (com.alibaba.druid.sql.ast.expr.SQLIntegerExpr)33 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)32 SQLPropertyExpr (com.alibaba.druid.sql.ast.expr.SQLPropertyExpr)30 ArrayList (java.util.ArrayList)30 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)28 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)25 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)25 ParserException (com.alibaba.druid.sql.parser.ParserException)25 SQLObject (com.alibaba.druid.sql.ast.SQLObject)24 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)23 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)20 SQLOrderBy (com.alibaba.druid.sql.ast.SQLOrderBy)17 SQLSelectQuery (com.alibaba.druid.sql.ast.statement.SQLSelectQuery)16 SQLCharExpr (com.alibaba.druid.sql.ast.expr.SQLCharExpr)15 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)15 SQLSelectQueryBlock (com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock)15