Search in sources :

Example 6 with SQLCommentHint

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

the class MySqlOutputVisitor method visit.

@Override
public boolean visit(MySqlDeleteStatement x) {
    print0(ucase ? "DELETE " : "delete ");
    for (int i = 0, size = x.getHintsSize(); i < size; ++i) {
        SQLCommentHint hint = x.getHints().get(i);
        hint.accept(this);
        print(' ');
    }
    if (x.isLowPriority()) {
        print0(ucase ? "LOW_PRIORITY " : "low_priority ");
    }
    if (x.isQuick()) {
        print0(ucase ? "QUICK " : "quick ");
    }
    if (x.isIgnore()) {
        print0(ucase ? "IGNORE " : "ignore ");
    }
    if (x.getFrom() == null) {
        print0(ucase ? "FROM " : "from ");
        x.getTableSource().accept(this);
    } else {
        x.getTableSource().accept(this);
        println();
        print0(ucase ? "FROM " : "from ");
        x.getFrom().accept(this);
    }
    if (x.getUsing() != null) {
        println();
        print0(ucase ? "USING " : "using ");
        x.getUsing().accept(this);
    }
    if (x.getWhere() != null) {
        println();
        incrementIndent();
        print0(ucase ? "WHERE " : "where ");
        x.getWhere().setParent(x);
        x.getWhere().accept(this);
        decrementIndent();
    }
    if (x.getOrderBy() != null) {
        println();
        x.getOrderBy().accept(this);
    }
    if (x.getLimit() != null) {
        println();
        x.getLimit().accept(this);
    }
    return false;
}
Also used : SQLCommentHint(com.alibaba.druid.sql.ast.SQLCommentHint) MySqlForceIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint) SQLCommentHint(com.alibaba.druid.sql.ast.SQLCommentHint) MySqlUseIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint) MySqlIgnoreIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint)

Example 7 with SQLCommentHint

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

the class MySqlOutputVisitor method visit.

public boolean visit(MySqlSelectQueryBlock x) {
    if (x.getOrderBy() != null) {
        x.getOrderBy().setParent(x);
    }
    print0(ucase ? "SELECT " : "select ");
    for (int i = 0, size = x.getHintsSize(); i < size; ++i) {
        SQLCommentHint hint = x.getHints().get(i);
        hint.accept(this);
        print(' ');
    }
    if (SQLSetQuantifier.ALL == x.getDistionOption()) {
        print0(ucase ? "ALL " : "all ");
    } else if (SQLSetQuantifier.DISTINCT == x.getDistionOption()) {
        print0(ucase ? "DISTINCT " : "distinct ");
    } else if (SQLSetQuantifier.DISTINCTROW == x.getDistionOption()) {
        print0(ucase ? "DISTINCTROW " : "distinctrow ");
    }
    if (x.isHignPriority()) {
        print0(ucase ? "HIGH_PRIORITY " : "high_priority ");
    }
    if (x.isStraightJoin()) {
        print0(ucase ? "STRAIGHT_JOIN " : "straight_join ");
    }
    if (x.isSmallResult()) {
        print0(ucase ? "SQL_SMALL_RESULT " : "sql_small_result ");
    }
    if (x.isBigResult()) {
        print0(ucase ? "SQL_BIG_RESULT " : "sql_big_result ");
    }
    if (x.isBufferResult()) {
        print0(ucase ? "SQL_BUFFER_RESULT " : "sql_buffer_result ");
    }
    if (x.getCache() != null) {
        if (x.getCache().booleanValue()) {
            print0(ucase ? "SQL_CACHE " : "sql_cache ");
        } else {
            print0(ucase ? "SQL_NO_CACHE " : "sql_no_cache ");
        }
    }
    if (x.isCalcFoundRows()) {
        print0(ucase ? "SQL_CALC_FOUND_ROWS " : "sql_calc_found_rows ");
    }
    printSelectList(x.getSelectList());
    if (x.getInto() != null) {
        println();
        print0(ucase ? "INTO " : "into ");
        x.getInto().accept(this);
    }
    if (x.getFrom() != null) {
        println();
        print0(ucase ? "FROM " : "from ");
        x.getFrom().accept(this);
    }
    if (x.getWhere() != null) {
        println();
        print0(ucase ? "WHERE " : "where ");
        x.getWhere().setParent(x);
        x.getWhere().accept(this);
    }
    if (x.getGroupBy() != null) {
        println();
        x.getGroupBy().accept(this);
    }
    if (x.getOrderBy() != null) {
        println();
        x.getOrderBy().accept(this);
    }
    if (x.getLimit() != null) {
        println();
        x.getLimit().accept(this);
    }
    if (x.getProcedureName() != null) {
        print0(ucase ? " PROCEDURE " : " procedure ");
        x.getProcedureName().accept(this);
        if (!x.getProcedureArgumentList().isEmpty()) {
            print('(');
            printAndAccept(x.getProcedureArgumentList(), ", ");
            print(')');
        }
    }
    if (x.isForUpdate()) {
        println();
        print0(ucase ? "FOR UPDATE" : "for update");
        if (x.isNoWait()) {
            print0(ucase ? " NO_WAIT" : " no_wait");
        } else if (x.getWaitTime() != null) {
            print0(ucase ? " WAIT " : " wait ");
            x.getWaitTime().accept(this);
        }
    }
    if (x.isLockInShareMode()) {
        println();
        print0(ucase ? "LOCK IN SHARE MODE" : "lock in share mode");
    }
    return false;
}
Also used : SQLCommentHint(com.alibaba.druid.sql.ast.SQLCommentHint) MySqlForceIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint) SQLCommentHint(com.alibaba.druid.sql.ast.SQLCommentHint) MySqlUseIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint) MySqlIgnoreIndexHint(com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint)

Aggregations

SQLCommentHint (com.alibaba.druid.sql.ast.SQLCommentHint)7 MySqlForceIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlForceIndexHint)3 MySqlIgnoreIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlIgnoreIndexHint)3 MySqlUseIndexHint (com.alibaba.druid.sql.dialect.mysql.ast.MySqlUseIndexHint)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)2 ParserException (com.alibaba.druid.sql.parser.ParserException)2 SQLObject (com.alibaba.druid.sql.ast.SQLObject)1 MySqlCreateTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)1 MySqlExecuteStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlExecuteStatement)1 MySqlHelpStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlHelpStatement)1 MySqlHintStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlHintStatement)1 MySqlLockTableStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlLockTableStatement)1 MySqlPrepareStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlPrepareStatement)1 MySqlReplaceStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlReplaceStatement)1 MySqlSetCharSetStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetCharSetStatement)1 MySqlSetNamesStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSetNamesStatement)1 MySqlUnlockTablesStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUnlockTablesStatement)1 MysqlDeallocatePrepareStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MysqlDeallocatePrepareStatement)1 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)1 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)1