Skip to content

Commit

Permalink
queryon: do not addLimitOffset() if isCountRequest()
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrugz committed Oct 2, 2024
1 parent 02cb680 commit 8ff030d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion demo/qon-demo-springboot/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ logging:
#org.apache.shiro.realm.text.IniRealm: TRACE
org.springframework.boot.context.config.ConfigFileApplicationListener: DEBUG
#org.springframework.web: DEBUG
#tbrugz.queryon.QueryOn: DEBUG
#tbrugz.queryon.RequestSpec: TRACE
#tbrugz.queryon.action.QOnManage: INFO
#tbrugz.queryon.action.QOnManage: DEBUG
#tbrugz.queryon.diff: DEBUG
#tbrugz.queryon.util: DEBUG
#tbrugz.queryon.RequestSpec: TRACE
#tbrugz.sqldiff: DEBUG
#tbrugz.sqldump.cdi: DEBUG
#tbrugz.sqldump.util.ConnectionUtil: DEBUG
Expand Down
5 changes: 4 additions & 1 deletion qon-core/src/main/java/tbrugz/queryon/QueryOn.java
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,10 @@ public static SQL getSelectQuery(Relation relation, RequestSpec reqspec, Constra
finalMaxLimit = Math.min(finalMaxLimit, sql.limitMax);
}
//log.info("finalMaxLimit="+finalMaxLimit+" ; sql.limitMax="+sql.limitMax+" ; defaultLimit="+defaultLimit);
sql.addLimitOffset(loStrategy, getLimit(sql.limit, defaultLimit, finalMaxLimit), reqspec.offset);
int limit = getLimit(sql.limit, defaultLimit, finalMaxLimit);
if(sql.shouldAddLimitOffset(limit, reqspec.offset) && !reqspec.isCountRequest()) {
sql.addLimitOffset(loStrategy, limit, reqspec.offset);
}
//log.debug("addLimitOffset: sql:\n"+sql.getSql());

sql.applyCount(reqspec);
Expand Down
6 changes: 5 additions & 1 deletion qon-core/src/main/java/tbrugz/queryon/RequestSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -1357,5 +1357,9 @@ public DumpSyntaxInt getOutputSyntax() {
public boolean isPivotedQueryRequest() {
return oncols.size()>0 || onrows.size()>0;
}


public boolean isCountRequest() {
return count;
}

}
20 changes: 15 additions & 5 deletions qon-core/src/main/java/tbrugz/queryon/SQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ protected void addCount() {
}

public void applyCount(RequestSpec reqspec) {
if(!reqspec.count) { return; }
if(!reqspec.isCountRequest()) { return; }
addCount();
}

Expand Down Expand Up @@ -552,10 +552,20 @@ public void applyInsert(List<String> allColumnNames, List<String> columnNames, L
addLimitOffset(strategy, this.limit, offset);
}*/

protected void addLimitOffset(LimitOffsetStrategy strategy, Integer limit, int offset) throws ServletException {
if(limit==null) { limit = 0; }
else { applyedLimit = limit; }
if(limit<=0 && offset<=0) { return; }
protected boolean shouldAddLimitOffset(int limit, int offset) throws ServletException {
//if(limit==null) { limit = 0; }
if(limit<=0 && offset<=0) { return false; }
return true;
}

protected void addLimitOffset(LimitOffsetStrategy strategy, int limit, int offset) throws ServletException {
if(!shouldAddLimitOffset(limit, offset)) {
return;
}
if(limit>0) { applyedLimit = limit; }
//if(limit==null) { limit = 0; }
//else { applyedLimit = limit; }
//if(limit<=0 && offset<=0) { return; }
if(strategy==LimitOffsetStrategy.RESULTSET_CONTROL) { return; }

if(strategy==LimitOffsetStrategy.SQL_LIMIT_OFFSET) {
Expand Down

0 comments on commit 8ff030d

Please sign in to comment.