Skip to content

Support for COUNT #238

Closed
Closed

Description

@Seldaek

Another one:

        $sql = 'SELECT COUNT(*) count FROM package p WHERE p.suspect IS NOT NULL AND (p.replacementPackage IS NULL OR p.replacementPackage != "spam/spam")';

        return (int) $this->getEntityManager()->getConnection()->fetchOne($sql);

triggers Cannot cast mixed to int

From https://github.com/composer/packagist/blob/bb486fc455c7c59544dd23d7508fcdf0fcc02023/src/Entity/PackageRepository.php#L467-L469

Seems to me like count is a clear case of returning int, but maybe I missed something :)

Seems like support should work as per

public function aggregateFunctions(PDO $pdo)
{
$query = 'SELECT MAX(adaid), MIN(adaid), COUNT(adaid), AVG(adaid) FROM ada WHERE adaid = 1';
$stmt = $pdo->query($query, PDO::FETCH_ASSOC);
assertType('PDOStatement<array{MAX(adaid): int<-2147483648, 2147483647>|null, MIN(adaid): int<-2147483648, 2147483647>|null, COUNT(adaid): int, AVG(adaid): float|null}>', $stmt);
}
but somehow it doesn't here. Not sure why.

Activity

  1. added
    bug
    on Feb 4, 2022
  2. staabm commented on Feb 4, 2022

    @staabm
    Owner

    Seems to me like count is a clear case of returning int, but maybe I missed something :)

    agree. at best it could maybe even be inferred as a 0|positive-int

  3. staabm commented on Feb 4, 2022

    @staabm
    Owner

    fixed the underlying problem, that no type could be inferred:

    grafik

    returning a 0|positive-int is still open and would require a proper sql parser, which is tracked in #123

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions