2727import static apijson .RequestMethod .DELETE ;
2828import static apijson .RequestMethod .GET ;
2929import static apijson .RequestMethod .GETS ;
30- import static apijson .RequestMethod .HEAD ;
3130import static apijson .RequestMethod .HEADS ;
3231import static apijson .RequestMethod .POST ;
3332import static apijson .RequestMethod .PUT ;
@@ -3942,28 +3941,30 @@ public static String getSQL(AbstractSQLConfig config) throws Exception {
39423941 if (config .isOracle ()) {
39433942 //When config's database is oracle,Using subquery since Oracle12 below does not support OFFSET FETCH paging syntax.
39443943 //针对oracle分组后条数的统计
3945- if ((config .getMethod () == HEAD || config .getMethod () == HEADS )
3946- && StringUtil .isNotEmpty (config .getGroup (),true )){
3944+ if (StringUtil .isNotEmpty (config .getGroup (),true ) && RequestMethod .isHeadMethod (config .getMethod (), true )){
39473945 return explain + "SELECT count(*) FROM (SELECT " + (config .getCache () == JSONRequest .CACHE_RAM ? "SQL_NO_CACHE " : "" ) + column + " FROM " + getConditionString (column , tablePath , config ) + ") " + config .getLimitString ();
39483946 }
3947+
39493948 String sql = "SELECT " + (config .getCache () == JSONRequest .CACHE_RAM ? "SQL_NO_CACHE " : "" ) + column + " FROM " + getConditionString (column , tablePath , config );
3950- return explain + config .getOraclePageSql (config , sql );
3949+ return explain + config .getOraclePageSql (sql );
39513950 }
3951+
39523952 return explain + "SELECT " + (config .getCache () == JSONRequest .CACHE_RAM ? "SQL_NO_CACHE " : "" ) + column + " FROM " + getConditionString (column , tablePath , config ) + config .getLimitString ();
39533953 }
3954- }
3955-
3954+ }
3955+
39563956 /**Oracle的分页获取
39573957 * @param config
39583958 * @param sql
39593959 * @return
39603960 */
3961- private String getOraclePageSql (AbstractSQLConfig config , String sql ) {
3962- int offset = getOffset (config .getPage (), config .getCount ());
3963- String pageSql ;
3964- pageSql = "SELECT * FROM (SELECT t.*,ROWNUM RN FROM (" + sql + ") t WHERE ROWNUM <= " + (offset + count ) + ") WHERE RN > " + offset ;
3965- return pageSql ;
3966- }
3961+ protected String getOraclePageSql (String sql ) {
3962+ int count = getCount ();
3963+ int offset = getOffset (getPage (), count );
3964+ String alias = getAliasWithQuote ();
3965+
3966+ return "SELECT * FROM (SELECT " + alias + ".*, ROWNUM RN FROM (" + sql + ") " + alias + " WHERE ROWNUM <= " + (offset + count ) + ") WHERE RN > " + offset ;
3967+ }
39673968
39683969 /**获取条件SQL字符串
39693970 * @param column
@@ -3981,16 +3982,19 @@ private static String getConditionString(String column, String table, AbstractSQ
39813982 }
39823983
39833984 //根据方法不同,聚合语句不同。GROUP BY 和 HAVING 可以加在 HEAD 上, HAVING 可以加在 PUT, DELETE 上,GET 全加,POST 全都不加
3984- String aggregation = "" ;
3985+ String aggregation ;
39853986 if (RequestMethod .isGetMethod (config .getMethod (), true )) {
39863987 aggregation = config .getGroupString (true ) + config .getHavingString (true ) + config .getOrderString (true );
39873988 }
3988- if (RequestMethod .isHeadMethod (config .getMethod (), true )) { // TODO 加参数 isPagenation 判断是 GET 内分页 query:2 查总数,不用加这些条件
3989+ else if (RequestMethod .isHeadMethod (config .getMethod (), true )) { // TODO 加参数 isPagenation 判断是 GET 内分页 query:2 查总数,不用加这些条件
39893990 aggregation = config .getGroupString (true ) + config .getHavingString (true ) ;
39903991 }
3991- if (config .getMethod () == PUT || config .getMethod () == DELETE ) {
3992+ else if (config .getMethod () == PUT || config .getMethod () == DELETE ) {
39923993 aggregation = config .getHavingString (true ) ;
39933994 }
3995+ else {
3996+ aggregation = "" ;
3997+ }
39943998
39953999 String condition = table + config .getJoinString () + where + aggregation ;
39964000 ; //+ config.getLimitString();
0 commit comments