Skip to content
This repository was archived by the owner on Jun 6, 2026. It is now read-only.
This repository was archived by the owner on Jun 6, 2026. It is now read-only.

count query fails when placeholders in select #168

Description

@greg606

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.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions