Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractSQLQuery.getResults is not correct on return values #854

Closed
bbakerman opened this issue Jul 17, 2014 · 1 comment
Closed

AbstractSQLQuery.getResults is not correct on return values #854

bbakerman opened this issue Jul 17, 2014 · 1 comment
Labels
bug
Milestone

Comments

@bbakerman
Copy link
Contributor

@bbakerman bbakerman commented Jul 17, 2014

There is a minor bug in the getResults such that it respects the input limit and offset but the search result return value is incorrect.

This is because a "queryMetadata.reset()" call is made in the inner list() call and the original limit/offet is lost

I am creating a fork to patch this but in shorts its

@Override
    public <RT> SearchResults<RT> listResults(Expression<RT> expr) {
        QueryModifiers originalModifiers = queryMixin.getMetadata().getModifiers();
        try {
            if (configuration.getTemplates().isCountViaAnalytics()) {
                List<RT> results;
                try {
                    queryMixin.addFlag(rowCountFlag);
                    getLastCell = true;
                    results = list(expr);
                } finally {
                    queryMixin.removeFlag(rowCountFlag);
                }
                long total;
                if (!results.isEmpty()) {
                    if (lastCell instanceof Number) {
                        total = ((Number)lastCell).longValue();
                    } else {
                        throw new IllegalStateException("Unsupported lastCell instance " + lastCell);
                    }
                } else {
                    total = count();
                }
                return new SearchResults<RT>(results, originalModifiers, total);

            } else {
                queryMixin.addProjection(expr);
                long total = count();
                if (total > 0) {
                    queryMixin.getMetadata().clearProjection();
                    return new SearchResults<RT>(list(expr), originalModifiers, total);
                } else {
                    return SearchResults.emptyResults();
                }
            }

        } finally {
            getLastCell = false;
            reset();
        }
    }
bbakerman added a commit to atlassian/querydsl that referenced this issue Jul 17, 2014
bbakerman added a commit to atlassian/querydsl that referenced this issue Jul 17, 2014
@timowest timowest added the bug label Jul 17, 2014
@timowest timowest added this to the 3.4.2 milestone Jul 17, 2014
@timowest timowest added the fixed label Jul 17, 2014
timowest added a commit that referenced this issue Jul 19, 2014
#854 - fixed limit / offset resetting
@timowest timowest modified the milestone: 3.4.2 Jul 19, 2014
@timowest timowest removed the fixed label Jul 19, 2014
@timowest timowest closed this Jul 19, 2014
@timowest
Copy link
Member

@timowest timowest commented Jul 29, 2014

Released in 3.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.