Package com.alibaba.druid.sql.dialect.mysql.ast.statement

Examples of com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock$Limit


            return queryRest(select);
        }

        accept(Token.SELECT);

        MySqlSelectQueryBlock queryBlock = new MySqlSelectQueryBlock();

        if (lexer.token() == (Token.DISTINCT)) {
            queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
            lexer.nextToken();
        } else if (identifierEquals("DISTINCTROW")) {
            queryBlock.setDistionOption(SQLSetQuantifier.DISTINCTROW);
            lexer.nextToken();
        } else if (lexer.token() == (Token.ALL)) {
            queryBlock.setDistionOption(SQLSetQuantifier.ALL);
            lexer.nextToken();
        }

        if (identifierEquals("HIGH_PRIORITY")) {
            queryBlock.setHignPriority(true);
            lexer.nextToken();
        }

        if (identifierEquals("STRAIGHT_JOIN")) {
            queryBlock.setStraightJoin(true);
            lexer.nextToken();
        }

        if (identifierEquals("SQL_SMALL_RESULT")) {
            queryBlock.setSmallResult(true);
            lexer.nextToken();
        }

        if (identifierEquals("SQL_BIG_RESULT")) {
            queryBlock.setBigResult(true);
            lexer.nextToken();
        }

        if (identifierEquals("SQL_BUFFER_RESULT")) {
            queryBlock.setBufferResult(true);
            lexer.nextToken();
        }

        if (identifierEquals("SQL_CACHE")) {
            queryBlock.setCache(true);
            lexer.nextToken();
        }

        if (identifierEquals("SQL_NO_CACHE")) {
            queryBlock.setCache(false);
            lexer.nextToken();
        }

        if (identifierEquals("SQL_CALC_FOUND_ROWS")) {
            queryBlock.setCalcFoundRows(true);
            lexer.nextToken();
        }

        parseSelectList(queryBlock);

        if (lexer.token() == (Token.INTO)) {
            lexer.nextToken();
            acceptIdentifier("OUTFILE");
            SQLExpr outFile = expr();
            queryBlock.setOutFile(outFile);

            if (identifierEquals("FIELDS") || identifierEquals("COLUMNS")) {
                lexer.nextToken();

                if (identifierEquals("TERMINATED")) {
                    lexer.nextToken();
                    accept(Token.BY);
                }
                queryBlock.setOutFileColumnsTerminatedBy((SQLLiteralExpr) expr());

                if (identifierEquals("OPTIONALLY")) {
                    lexer.nextToken();
                    queryBlock.setOutFileColumnsEnclosedOptionally(true);
                }

                if (identifierEquals("ENCLOSED")) {
                    lexer.nextToken();
                    accept(Token.BY);
                    queryBlock.setOutFileColumnsEnclosedBy((SQLLiteralExpr) expr());
                }

                if (identifierEquals("ESCAPED")) {
                    lexer.nextToken();
                    accept(Token.BY);
                    queryBlock.setOutFileColumnsEscaped((SQLLiteralExpr) expr());
                }
            }

            if (identifierEquals("LINES")) {
                lexer.nextToken();

                if (identifierEquals("STARTING")) {
                    lexer.nextToken();
                    accept(Token.BY);
                    queryBlock.setOutFileLinesStartingBy((SQLLiteralExpr) expr());
                } else {
                    identifierEquals("TERMINATED");
                    lexer.nextToken();
                    accept(Token.BY);
                    queryBlock.setOutFileLinesTerminatedBy((SQLLiteralExpr) expr());
                }
            }
        }

        parseFrom(queryBlock);

        parseWhere(queryBlock);

        parseGroupBy(queryBlock);

        queryBlock.setOrderBy(this.createExprParser().parseOrderBy());

        if (lexer.token() == Token.LIMIT) {
            lexer.nextToken();

            MySqlSelectQueryBlock.Limit limit = new MySqlSelectQueryBlock.Limit();

            SQLExpr temp = this.createExprParser().expr();
            if (lexer.token() == (Token.COMMA)) {
                limit.setOffset(temp);
                lexer.nextToken();
                limit.setRowCount(createExprParser().expr());
            } else if (identifierEquals("OFFSET")) {
                limit.setRowCount(temp);
                lexer.nextToken();
                limit.setOffset(createExprParser().expr());
            } else {
                limit.setRowCount(temp);
            }

            queryBlock.setLimit(limit);
        }

        if (identifierEquals("PROCEDURE")) {
            lexer.nextToken();
            throw new ParserException("TODO");
        }

        if (lexer.token() == Token.INTO) {
            lexer.nextToken();
            throw new ParserException("TODO");
        }

        if (lexer.token() == Token.FOR) {
            lexer.nextToken();
            accept(Token.UPDATE);

            queryBlock.setForUpdate(true);
        }

        if (lexer.token() == Token.LOCK) {
            lexer.nextToken();
            accept(Token.IN);
            acceptIdentifier("SHARE");
            acceptIdentifier("MODE");
            queryBlock.setLockInShareMode(true);
        }

        return queryRest(queryBlock);
    }
View Full Code Here


        return SQLUtils.toSQLString(countStmt, dbType);
    }

    private static SQLSelectQueryBlock createQueryBlock(String dbType) {
        if (JdbcConstants.MYSQL.equals(dbType)) {
            return new MySqlSelectQueryBlock();
        }

        if (JdbcConstants.ORACLE.equals(dbType)) {
            return new OracleSelectQueryBlock();
        }
View Full Code Here

    private static void clearOrderBy(SQLSelectQuery query) {
        if (query instanceof SQLSelectQueryBlock) {
            SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) query;
            if (queryBlock instanceof MySqlSelectQueryBlock) {
                MySqlSelectQueryBlock mysqlQueryBlock = (MySqlSelectQueryBlock) queryBlock;
                if (mysqlQueryBlock.getOrderBy() != null) {
                    mysqlQueryBlock.setOrderBy(null);
                }
            } else if (queryBlock instanceof PGSelectQueryBlock) {
                PGSelectQueryBlock pgQueryBlock = (PGSelectQueryBlock) queryBlock;
                if (pgQueryBlock.getOrderBy() != null) {
                    pgQueryBlock.setOrderBy(null);
View Full Code Here

    @Override
    public boolean visit(MySqlUnionQuery x) {
        {
            boolean needParen = false;
            if (x.getLeft() instanceof MySqlSelectQueryBlock) {
                MySqlSelectQueryBlock right = (MySqlSelectQueryBlock) x.getLeft();
                if (right.getOrderBy() != null || right.getLimit() != null) {
                    needParen = true;
                }
            }
            if (needParen) {
                print('(');
                x.getLeft().accept(this);
                print(')');
            } else {
                x.getLeft().accept(this);
            }
        }
        println();
        print(x.getOperator().name);
        println();

        boolean needParen = false;

        if (x.getOrderBy() != null || x.getLimit() != null) {
            needParen = true;
        } else if (x.getRight() instanceof MySqlSelectQueryBlock) {
            MySqlSelectQueryBlock right = (MySqlSelectQueryBlock) x.getRight();
            if (right.getOrderBy() != null || right.getLimit() != null) {
                needParen = true;
            }
        }

        if (needParen) {
View Full Code Here

       
        SQLSelectStatement selectStmt = (SQLSelectStatement) stmt;
       
        SQLSelect select = selectStmt.getSelect();
        Assert.assertNotNull(select.getQuery());
        MySqlSelectQueryBlock queryBlock = (MySqlSelectQueryBlock) select.getQuery();
        Assert.assertNotNull(queryBlock.getOrderBy());
       
        print(statementList);

        Assert.assertEquals(1, statementList.size());
View Full Code Here

    @Override
    public boolean visit(MySqlUnionQuery x) {
        {
            boolean needParen = false;
            if (x.getLeft() instanceof MySqlSelectQueryBlock) {
                MySqlSelectQueryBlock right = (MySqlSelectQueryBlock) x.getLeft();
                if (right.getOrderBy() != null || right.getLimit() != null) {
                    needParen = true;
                }
            }
            if (needParen) {
                print('(');
                x.getLeft().accept(this);
                print(')');
            } else {
                x.getLeft().accept(this);
            }
        }
        println();
        print(x.getOperator().name);
        println();

        boolean needParen = false;

        if (x.getOrderBy() != null || x.getLimit() != null) {
            needParen = true;
        } else if (x.getRight() instanceof MySqlSelectQueryBlock) {
            MySqlSelectQueryBlock right = (MySqlSelectQueryBlock) x.getRight();
            if (right.getOrderBy() != null || right.getLimit() != null) {
                needParen = true;
            }
        }

        if (needParen) {
View Full Code Here

            accept(Token.RPAREN);

            return queryRest(select);
        }

        MySqlSelectQueryBlock queryBlock = new MySqlSelectQueryBlock();

        if (lexer.token() == Token.SELECT) {
            lexer.nextToken();

            if (lexer.token() == Token.HINT) {
                this.exprParser.parseHints(queryBlock.getHints());
            }

            if (lexer.token() == Token.COMMENT) {
                lexer.nextToken();
            }

            if (lexer.token() == (Token.DISTINCT)) {
                queryBlock.setDistionOption(SQLSetQuantifier.DISTINCT);
                lexer.nextToken();
            } else if (identifierEquals("DISTINCTROW")) {
                queryBlock.setDistionOption(SQLSetQuantifier.DISTINCTROW);
                lexer.nextToken();
            } else if (lexer.token() == (Token.ALL)) {
                queryBlock.setDistionOption(SQLSetQuantifier.ALL);
                lexer.nextToken();
            }

            if (identifierEquals("HIGH_PRIORITY")) {
                queryBlock.setHignPriority(true);
                lexer.nextToken();
            }

            if (identifierEquals("STRAIGHT_JOIN")) {
                queryBlock.setStraightJoin(true);
                lexer.nextToken();
            }

            if (identifierEquals("SQL_SMALL_RESULT")) {
                queryBlock.setSmallResult(true);
                lexer.nextToken();
            }

            if (identifierEquals("SQL_BIG_RESULT")) {
                queryBlock.setBigResult(true);
                lexer.nextToken();
            }

            if (identifierEquals("SQL_BUFFER_RESULT")) {
                queryBlock.setBufferResult(true);
                lexer.nextToken();
            }

            if (identifierEquals("SQL_CACHE")) {
                queryBlock.setCache(true);
                lexer.nextToken();
            }

            if (identifierEquals("SQL_NO_CACHE")) {
                queryBlock.setCache(false);
                lexer.nextToken();
            }

            if (identifierEquals("SQL_CALC_FOUND_ROWS")) {
                queryBlock.setCalcFoundRows(true);
                lexer.nextToken();
            }

            parseSelectList(queryBlock);
           
            parseInto(queryBlock);
        }

        parseFrom(queryBlock);

        parseWhere(queryBlock);

        parseGroupBy(queryBlock);

        queryBlock.setOrderBy(this.exprParser.parseOrderBy());

        if (lexer.token() == Token.LIMIT) {
            queryBlock.setLimit(parseLimit());
        }

        if (lexer.token() == Token.PROCEDURE) {
            lexer.nextToken();
            throw new ParserException("TODO");
        }

        parseInto(queryBlock);

        if (lexer.token() == Token.FOR) {
            lexer.nextToken();
            accept(Token.UPDATE);

            queryBlock.setForUpdate(true);
        }

        if (lexer.token() == Token.LOCK) {
            lexer.nextToken();
            accept(Token.IN);
            acceptIdentifier("SHARE");
            acceptIdentifier("MODE");
            queryBlock.setLockInShareMode(true);
        }

        return queryRest(queryBlock);
    }
View Full Code Here

        SQLSelectStatement selectStmt = (SQLSelectStatement) stmt;

        SQLSelect select = selectStmt.getSelect();
        Assert.assertNotNull(select.getQuery());
        MySqlSelectQueryBlock queryBlock = (MySqlSelectQueryBlock) select.getQuery();
        Assert.assertNull(queryBlock.getOrderBy());

        print(statementList);

        Assert.assertEquals(1, statementList.size());
View Full Code Here

       
        SQLSelectStatement selectStmt = (SQLSelectStatement) stmt;
       
        SQLSelect select = selectStmt.getSelect();
        Assert.assertNotNull(select.getQuery());
        MySqlSelectQueryBlock queryBlock = (MySqlSelectQueryBlock) select.getQuery();
        Assert.assertNull(queryBlock.getOrderBy());
       
        print(statementList);

        Assert.assertEquals(1, statementList.size());
View Full Code Here

        SQLSelectStatement selectStmt = (SQLSelectStatement) stmt;

        SQLSelect select = selectStmt.getSelect();
        Assert.assertNotNull(select.getQuery());
        MySqlSelectQueryBlock queryBlock = (MySqlSelectQueryBlock) select.getQuery();
        Assert.assertNull(queryBlock.getOrderBy());

        print(statementList);

        Assert.assertEquals(1, statementList.size());
View Full Code Here

TOP

Related Classes of com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock$Limit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.