Skip to content

QB countAllResults shouldn't use LIMIT settings #2152

Description

@tangix

Describe the bug
When running a query and re-using the same WHERE and LIMIT settings for the countAllResults, the count will be zero is the offset parameter to get() is > 0.
For example this code will produce the wrong $total count:

$builder = db_connect()->table('users');
$builder->select('userID,firstname,lastname,email')
->where('companyLink !=', 0);
$query = $builder->get(50, 50, false, false); // Don't reset QB
$total = $builder->countAllResults($builder);

The get() is configured not to reset the QB state and thus the LIMIT 50, 50 will be in effect when running the countAllResults() query. Since LIMIT 50, 50 is in effect, the first (and only) result row of the the COUNT(*) query is lost.

CodeIgniter 4 version
4.0.0-beta4

Affected module(s)
Database\BaseBuilder

Expected behavior, and steps to reproduce if appropriate
Getting anything else than zero back.

Context
PHP 7.3.8

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions