Search in sources :

Example 61 with SQLASTOutputVisitor

use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.

the class MySqlParameterizedOutputVisitorTest_46 method test_for_parameterize.

public void test_for_parameterize() throws Exception {
    final DbType dbType = JdbcConstants.MYSQL;
    String sql = "SELECT COUNT(*) AS count, `ipv_uv_1d_001` AS col FROM ( (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) UNION ALL (SELECT ipv_uv_1d_001 FROM `cbu_da_dihu_16`.`ads_tb_sycm_eff_slr_itm_1d_s015_p033` WHERE `auto_seq_id` > ? LIMIT ?) ) ads_tb_sycm_eff_slr_itm_1d_s015_p033 GROUP BY col ORDER BY col DESC";
    SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
    List<SQLStatement> stmtList = parser.parseStatementList();
    SQLStatement statement = stmtList.get(0);
    StringBuilder out = new StringBuilder();
    SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
    List<Object> parameters = new ArrayList<Object>();
    visitor.setParameterized(true);
    visitor.setParameterizedMergeInList(true);
    visitor.setParameters(parameters);
    /*visitor.setPrettyFormat(false);*/
    statement.accept(visitor);
    /* JSONArray array = new JSONArray();
        for(String table : visitor.getTables()){
            array.add(table.replaceAll("`",""));
        }*/
    String psql = out.toString();
    System.out.println(psql);
    assertEquals("SELECT COUNT(*) AS count, `ipv_uv_1d_001` AS col\n" + "FROM (\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + "\tUNION ALL\n" + "\t(SELECT ipv_uv_1d_001\n" + "\tFROM cbu_da_dihu.ads_tb_sycm_eff_slr_itm_1d_s015_p\n" + "\tWHERE `auto_seq_id` > ?\n" + "\tLIMIT ?)\n" + ") ads_tb_sycm_eff_slr_itm_1d_s015_p033\n" + "GROUP BY col\n" + "ORDER BY col DESC", psql);
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) ArrayList(java.util.ArrayList) SQLASTOutputVisitor(com.alibaba.druid.sql.visitor.SQLASTOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DbType(com.alibaba.druid.DbType)

Example 62 with SQLASTOutputVisitor

use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.

the class MySqlParameterizedOutputVisitorTest_55 method test_for_parameterize.

public void test_for_parameterize() throws Exception {
    final DbType dbType = JdbcConstants.MYSQL;
    String sql = "/* ///9fe39e72/ */SELECT fck1.fck_order_id, fck1.out_order_id, fck1.seller_nick, fck1.buyer_nick, fck1.seller_id, fck1.buyer_id, fck1.auction_id, fck1.auction_title, fck1.auction_price, fck1.buy_amount, fck1.fck_type, fck1.sub_fck_type, fck1.fail_reason, fck1.pay_status, fck1.logistics_status, fck1.out_trade_status, fck1.snap_path, fck1.gmt_create, fck1.status, ifnull(fck1.buyer_rate_status, 4) AS buyer_rate_status, ifnull(fck1.seller_rate_status, 4) AS seller_rate_status, fck1.auction_pict_url, fck1.seller_memo, fck1.buyer_memo, fck1.seller_flag, fck1.buyer_flag, fck1.buyer_message_path, fck1.refund_status, fck1.attributes, fck1.attributes_cc, fck1.gmt_modified, fck1.ip, fck1.end_time, fck1.pay_time, fck1.is_main, fck1.is_detail, fck1.point_rate, fck1.parent_id, fck1.adjust_fee, fck1.discount_fee, fck1.refund_fee, fck1.confirm_paid_fee, fck1.cod_status, fck1.trade_tag, fck1.shop_id, fck1.options, fck1.ignore_sold_quantity, fck1.from_group, fck1.gmt_create_tc FROM (SELECT fck_order_id FROM tc_fck_order AS tc_fck_order IGNORE INDEX (ind_fck_order_status, idx_sid_bt_st_im) WHERE is_main = 1 AND (fck_type = 2700 OR fck_type = 200 OR fck_type = 10000 OR fck_type = 610 OR fck_type = 600 OR fck_type = 300 OR fck_type = 100 OR fck_type = 500 OR fck_type = 900 OR fck_type = 620 OR fck_type = 630 OR fck_type = 650 OR fck_type = 1000 OR fck_type = 1001 OR fck_type = 710 OR fck_type = 1200 OR fck_type = 1201 OR fck_type = 1500 OR fck_type = 1600 OR fck_type = 2000 OR fck_type = 2400) AND seller_id = 2169996291 AND (sub_fck_type = 1 OR sub_fck_type = 901 OR sub_fck_type = 801 OR sub_fck_type = 701 OR sub_fck_type = 601 OR sub_fck_type = 2) AND status = 0 AND gmt_create >= DATE_FORMAT('2017-04-22 00:00:00', '%Y-%m-%d %T') AND gmt_create <= DATE_FORMAT('2017-05-07 23:59:59', '%Y-%m-%d %T') AND from_group = 0 ORDER BY gmt_create DESC LIMIT 900, 100) AS fck2, tc_fck_order AS fck1 WHERE fck2.fck_order_id = fck1.fck_order_id";
    SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
    List<SQLStatement> stmtList = parser.parseStatementList();
    SQLStatement statement = stmtList.get(0);
    StringBuilder out = new StringBuilder();
    SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
    List<Object> parameters = new ArrayList<Object>();
    visitor.setParameterized(true);
    visitor.setParameterizedMergeInList(true);
    visitor.setParameters(parameters);
    /*visitor.setPrettyFormat(false);*/
    statement.accept(visitor);
    /* JSONArray array = new JSONArray();
        for(String table : visitor.getTables()){
            array.add(table.replaceAll("`",""));
        }*/
    String psql = out.toString();
    System.out.println(psql);
    assertEquals("SELECT fck1.fck_order_id, fck1.out_order_id, fck1.seller_nick, fck1.buyer_nick, fck1.seller_id\n" + "\t, fck1.buyer_id, fck1.auction_id, fck1.auction_title, fck1.auction_price, fck1.buy_amount\n" + "\t, fck1.fck_type, fck1.sub_fck_type, fck1.fail_reason, fck1.pay_status, fck1.logistics_status\n" + "\t, fck1.out_trade_status, fck1.snap_path, fck1.gmt_create, fck1.status\n" + "\t, ifnull(fck1.buyer_rate_status, ?) AS buyer_rate_status\n" + "\t, ifnull(fck1.seller_rate_status, ?) AS seller_rate_status, fck1.auction_pict_url\n" + "\t, fck1.seller_memo, fck1.buyer_memo, fck1.seller_flag, fck1.buyer_flag, fck1.buyer_message_path\n" + "\t, fck1.refund_status, fck1.attributes, fck1.attributes_cc, fck1.gmt_modified, fck1.ip\n" + "\t, fck1.end_time, fck1.pay_time, fck1.is_main, fck1.is_detail, fck1.point_rate\n" + "\t, fck1.parent_id, fck1.adjust_fee, fck1.discount_fee, fck1.refund_fee, fck1.confirm_paid_fee\n" + "\t, fck1.cod_status, fck1.trade_tag, fck1.shop_id, fck1.options, fck1.ignore_sold_quantity\n" + "\t, fck1.from_group, fck1.gmt_create_tc\n" + "FROM (\n" + "\tSELECT fck_order_id\n" + "\tFROM tc_fck_order tc_fck_order IGNORE INDEX (ind_fck_order_status, idx_sid_bt_st_im)\n" + "\tWHERE is_main = ?\n" + "\t\tAND (fck_type = ?)\n" + "\t\tAND seller_id = ?\n" + "\t\tAND (sub_fck_type = ?)\n" + "\t\tAND status = ?\n" + "\t\tAND gmt_create >= DATE_FORMAT(?, '%Y-%m-%d %T')\n" + "\t\tAND gmt_create <= DATE_FORMAT(?, '%Y-%m-%d %T')\n" + "\t\tAND from_group = ?\n" + "\tORDER BY gmt_create DESC\n" + "\tLIMIT ?, ?\n" + ") fck2, tc_fck_order fck1\n" + "WHERE fck2.fck_order_id = fck1.fck_order_id", psql);
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) ArrayList(java.util.ArrayList) SQLASTOutputVisitor(com.alibaba.druid.sql.visitor.SQLASTOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DbType(com.alibaba.druid.DbType)

Example 63 with SQLASTOutputVisitor

use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.

the class MySqlParameterizedOutputVisitorTest_57 method test_for_parameterize.

public void test_for_parameterize() throws Exception {
    final DbType dbType = JdbcConstants.MYSQL;
    String sql = "select `ktv_resource`.`VERSION` from `ktv_resource_0118` `ktv_resource` " + "where ((`ktv_resource`.`BUYER_ID` = 736485494) " + "   AND (`ktv_resource`.`STATUS` = 1) " + "   AND (`ktv_resource`.`START_TIME` <= '2017-10-24 00:27:21.839') " + "   AND (`ktv_resource`.`END_TIME` >= '2017-10-24 00:27:21.839') " + "   AND (`ktv_resource`.`seller_id` = 2933220011) " + "   AND (`ktv_resource`.`AVAILABLE_COUNT` IS NULL " + "       OR (`ktv_resource`.`AVAILABLE_COUNT` > 0) " + "       OR (`ktv_resource`.`AVAILABLE_COUNT` = -1))" + ") limit 0,20";
    SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType, SQLParserFeature.EnableSQLBinaryOpExprGroup);
    List<SQLStatement> stmtList = parser.parseStatementList();
    SQLStatement stmt = stmtList.get(0);
    StringBuilder out = new StringBuilder();
    SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
    List<Object> parameters = new ArrayList<Object>();
    visitor.setParameterized(true);
    visitor.setParameterizedMergeInList(true);
    visitor.setParameters(parameters);
    /*visitor.setPrettyFormat(false);*/
    stmt.accept(visitor);
    /* JSONArray array = new JSONArray();
        for(String table : visitor.getTables()){
            array.add(table.replaceAll("`",""));
        }*/
    String psql = out.toString();
    System.out.println(psql);
    assertEquals("SELECT `ktv_resource`.`VERSION`\n" + "FROM ktv_resource `ktv_resource`\n" + "WHERE `ktv_resource`.`BUYER_ID` = ?\n" + "\tAND `ktv_resource`.`STATUS` = ?\n" + "\tAND `ktv_resource`.`START_TIME` <= ?\n" + "\tAND `ktv_resource`.`END_TIME` >= ?\n" + "\tAND `ktv_resource`.`seller_id` = ?\n" + "\tAND (`ktv_resource`.`AVAILABLE_COUNT` IS NULL\n" + "\t\tOR `ktv_resource`.`AVAILABLE_COUNT` > ?\n" + "\t\tOR `ktv_resource`.`AVAILABLE_COUNT` = ?)\n" + "LIMIT ?, ?", psql);
    String rsql = SQLUtils.format(psql, JdbcConstants.MYSQL, parameters);
    System.out.println(rsql);
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) ArrayList(java.util.ArrayList) SQLASTOutputVisitor(com.alibaba.druid.sql.visitor.SQLASTOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DbType(com.alibaba.druid.DbType)

Example 64 with SQLASTOutputVisitor

use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.

the class MySqlParameterizedOutputVisitorTest_52_schema method test_for_parameterize.

public void test_for_parameterize() throws Exception {
    final DbType dbType = JdbcConstants.MYSQL;
    String sql = "UPDATE `buyer_0158`.xc_yy_order_1082\n" + "SET `ALIPAY_BUYER_ID` = 1025, `GMT_MODIFIED` = 'aaaa'\n" + "WHERE `PAY_ORDER_ID` = 'kkk'";
    SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
    List<SQLStatement> stmtList = parser.parseStatementList();
    SQLStatement statement = stmtList.get(0);
    StringBuilder out = new StringBuilder();
    SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
    List<Object> parameters = new ArrayList<Object>();
    visitor.setParameterized(true);
    visitor.setParameterizedMergeInList(true);
    visitor.setParameters(parameters);
    /*visitor.setPrettyFormat(false);*/
    statement.accept(visitor);
    /* JSONArray array = new JSONArray();
        for(String table : visitor.getTables()){
            array.add(table.replaceAll("`",""));
        }*/
    String psql = out.toString();
    System.out.println(psql);
    assertEquals("UPDATE buyer.xc_yy_order\n" + "SET `ALIPAY_BUYER_ID` = ?, `GMT_MODIFIED` = ?\n" + "WHERE `PAY_ORDER_ID` = ?", psql);
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) ArrayList(java.util.ArrayList) SQLASTOutputVisitor(com.alibaba.druid.sql.visitor.SQLASTOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DbType(com.alibaba.druid.DbType)

Example 65 with SQLASTOutputVisitor

use of com.alibaba.druid.sql.visitor.SQLASTOutputVisitor in project druid by alibaba.

the class MySqlParameterizedOutputVisitorTest_56 method test_for_parameterize.

public void test_for_parameterize() throws Exception {
    final DbType dbType = JdbcConstants.MYSQL;
    String sql = "/* 0b802ab415058233338893940e1882/0.1.2.23//abd5b625/ */select `ktv_resource`.`RESOURCE_ID`,`ktv_resource`.`RESOURCE_PROVIDER`,`ktv_resource`.`KTV_ID`,`ktv_resource`.`RESOURCE_TYPE`,`ktv_resource`.`SUB_RESOURCE_TYPE`,`ktv_resource`.`STATUS`,`ktv_resource`.`START_TIME`,`ktv_resource`.`END_TIME`,`ktv_resource`.`FEATURE`,`ktv_resource`.`GMT_CREATED`,`ktv_resource`.`GMT_MODIFIED`,`ktv_resource`.`source`,`ktv_resource`.`seller_id`,`ktv_resource`.`original_Resource_Id`,`ktv_resource`.`business_unit`,`ktv_resource`.`resource_code`,`ktv_resource`.`OPTIONS`,`ktv_resource`.`AVAILABLE_COUNT`,`ktv_resource`.`TOTAL_COUNT`,`ktv_resource`.`OUT_INSTANCE_ID`,`ktv_resource`.`CONSUME_ID`,`ktv_resource`.`GROUP_ID`,`ktv_resource`.`BUSINESS_ID`,`ktv_resource`.`rule`,`ktv_resource`.`market_place`,`ktv_resource`.`VERSION` from `ktv_resource_0062` `ktv_resource` where ((`ktv_resource`.`KTV_ID` = 880693310) AND (`ktv_resource`.`STATUS` = 1) AND (`ktv_resource`.`START_TIME` <= '2017-09-19 20:15:34.199') AND (`ktv_resource`.`END_TIME` >= '2017-09-19 20:15:34.199') AND (`ktv_resource`.`seller_id` IN (2680068332)) AND (`ktv_resource`.`AVAILABLE_COUNT` IS NULL OR (`ktv_resource`.`AVAILABLE_COUNT` > 0) OR (`ktv_resource`.`AVAILABLE_COUNT` = -1))) limit 0,30";
    SQLStatementParser parser = SQLParserUtils.createSQLStatementParser(sql, dbType);
    List<SQLStatement> stmtList = parser.parseStatementList();
    SQLStatement statement = stmtList.get(0);
    StringBuilder out = new StringBuilder();
    SQLASTOutputVisitor visitor = SQLUtils.createOutputVisitor(out, JdbcConstants.MYSQL);
    List<Object> parameters = new ArrayList<Object>();
    visitor.setParameterized(true);
    visitor.setParameterizedMergeInList(true);
    visitor.setParameters(parameters);
    /*visitor.setPrettyFormat(false);*/
    statement.accept(visitor);
    /* JSONArray array = new JSONArray();
        for(String table : visitor.getTables()){
            array.add(table.replaceAll("`",""));
        }*/
    String psql = out.toString();
    System.out.println(psql);
    assertEquals("SELECT `ktv_resource`.`RESOURCE_ID`, `ktv_resource`.`RESOURCE_PROVIDER`, `ktv_resource`.`KTV_ID`, `ktv_resource`.`RESOURCE_TYPE`, `ktv_resource`.`SUB_RESOURCE_TYPE`\n" + "\t, `ktv_resource`.`STATUS`, `ktv_resource`.`START_TIME`, `ktv_resource`.`END_TIME`, `ktv_resource`.`FEATURE`, `ktv_resource`.`GMT_CREATED`\n" + "\t, `ktv_resource`.`GMT_MODIFIED`, `ktv_resource`.`source`, `ktv_resource`.`seller_id`, `ktv_resource`.`original_Resource_Id`, `ktv_resource`.`business_unit`\n" + "\t, `ktv_resource`.`resource_code`, `ktv_resource`.`OPTIONS`, `ktv_resource`.`AVAILABLE_COUNT`, `ktv_resource`.`TOTAL_COUNT`, `ktv_resource`.`OUT_INSTANCE_ID`\n" + "\t, `ktv_resource`.`CONSUME_ID`, `ktv_resource`.`GROUP_ID`, `ktv_resource`.`BUSINESS_ID`, `ktv_resource`.`rule`, `ktv_resource`.`market_place`\n" + "\t, `ktv_resource`.`VERSION`\n" + "FROM ktv_resource `ktv_resource`\n" + "WHERE `ktv_resource`.`KTV_ID` = ?\n" + "\tAND `ktv_resource`.`STATUS` = ?\n" + "\tAND `ktv_resource`.`START_TIME` <= ?\n" + "\tAND `ktv_resource`.`END_TIME` >= ?\n" + "\tAND `ktv_resource`.`seller_id` IN (?)\n" + "\tAND (`ktv_resource`.`AVAILABLE_COUNT` IS NULL\n" + "\t\tOR `ktv_resource`.`AVAILABLE_COUNT` > ?\n" + "\t\tOR `ktv_resource`.`AVAILABLE_COUNT` = ?)\n" + "LIMIT ?, ?", psql);
    String rsql = SQLUtils.format(psql, JdbcConstants.MYSQL, parameters);
    System.out.println(rsql);
}
Also used : SQLStatementParser(com.alibaba.druid.sql.parser.SQLStatementParser) ArrayList(java.util.ArrayList) SQLASTOutputVisitor(com.alibaba.druid.sql.visitor.SQLASTOutputVisitor) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DbType(com.alibaba.druid.DbType)

Aggregations

SQLASTOutputVisitor (com.alibaba.druid.sql.visitor.SQLASTOutputVisitor)67 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)56 ArrayList (java.util.ArrayList)48 DbType (com.alibaba.druid.DbType)45 SQLStatementParser (com.alibaba.druid.sql.parser.SQLStatementParser)44 JSONArray (com.alibaba.fastjson.JSONArray)10 MySqlOutputVisitor (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor)3 OracleOutputVisitor (com.alibaba.druid.sql.dialect.oracle.visitor.OracleOutputVisitor)3 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)2 SQLAggregateExpr (com.alibaba.druid.sql.ast.expr.SQLAggregateExpr)2 SQLAllColumnExpr (com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr)2 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)2 SQLSelectGroupByClause (com.alibaba.druid.sql.ast.statement.SQLSelectGroupByClause)2 SQLSelectItem (com.alibaba.druid.sql.ast.statement.SQLSelectItem)2 DB2SelectQueryBlock (com.alibaba.druid.sql.dialect.db2.ast.stmt.DB2SelectQueryBlock)2 DB2OutputVisitor (com.alibaba.druid.sql.dialect.db2.visitor.DB2OutputVisitor)2 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)2 MySqlStatementParser (com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser)2 OracleSelectQueryBlock (com.alibaba.druid.sql.dialect.oracle.ast.stmt.OracleSelectQueryBlock)2 PGSelectQueryBlock (com.alibaba.druid.sql.dialect.postgresql.ast.stmt.PGSelectQueryBlock)2