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

Support for COUNT #238

Closed
Seldaek opened this issue Feb 3, 2022 · 2 comments
Closed

Support for COUNT #238

Seldaek opened this issue Feb 3, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@Seldaek
Copy link
Contributor

Seldaek commented Feb 3, 2022

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.

@staabm staabm added the bug Something isn't working label Feb 4, 2022
@staabm
Copy link
Owner

staabm commented Feb 4, 2022

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

@staabm
Copy link
Owner

staabm commented Feb 4, 2022

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

@staabm staabm mentioned this issue Feb 4, 2022
13 tasks
@staabm staabm closed this as completed Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants