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

count query fails when placeholders in select #168

Open
greg606 opened this issue Jan 31, 2016 · 0 comments
Open

count query fails when placeholders in select #168

greg606 opened this issue Jan 31, 2016 · 0 comments

Comments

@greg606
Copy link

greg606 commented Jan 31, 2016

Given the query

$qb->select("c, u, p, a, pd, ad, GEO_DISTANCE_BY_POSTAL_CODE('GB', :postcode, 'GB', ad.outerPostcode) AS distance");

the count query fails as it strips the select clause.

quick fix for it is like this:
from Ali/DatatableBundle/Util/Factory/Query/DoctrineBuilder.php:148

    /**
     * get total records
     * 
     * @return integer 
     */
    public function getTotalRecords()
    {
        $qb = clone $this->queryBuilder;
        $this->_addSearch($qb);
        $qb->resetDQLPart('orderBy');

        $gb = $qb->getDQLPart('groupBy');
        if (empty($gb) || !in_array($this->fields['_identifier_'], $gb))
        {
            $qb->select(" count({$this->fields['_identifier_']}), (:postcode) distance ");

            return $qb->getQuery()->getSingleResult()[1];
        }
        else
        {
            $qb->resetDQLPart('groupBy');
            $qb->select(" count(distinct {$this->fields['_identifier_']}) ");
            return $qb->getQuery()->getSingleScalarResult();
        }
    }

Of course it will break other datatables.
I think it should be catered for in more general way.
Other possible soloution - remove parameters bound.

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

No branches or pull requests

1 participant