Bug when call stored procedure #5239

Open
opened 2026-01-22 15:02:25 +01:00 by admin · 1 comment
Owner

Originally created by @PlamenVasilev on GitHub (Sep 2, 2016).

I have named query which calls stored procedure with one parameter.
I call the stored procedure with

$query = $this->createNativeNamedQuery('CallStoredProcedure')
              ->setParameter('id', $id);
return $query->getOneOrNullResult();

the stored procedure is something like:

BEGIN
if exists( select something from some_tabel where something) than
    select a,b,c,d from  some_tabel where something
end if;
END;

When i have row in the table the result is returned and everything is fine.
When there are now rows matched the stored procedure doesn't return anything and doctrine gives me SQLSTATE[HY000]: General error

the full backtrace is:

[1] Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000]: General error
    at n/a
        in /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 117

    at Doctrine\DBAL\Driver\PDOStatement->fetch('2')
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 164

    at Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData()
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php line 147

    at Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(object(PDOStatement), object(ResultSetMappingBuilder), array())
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 978

    at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, null)
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 924

    at Doctrine\ORM\AbstractQuery->execute(null, null)
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 766

    at Doctrine\ORM\AbstractQuery->getOneOrNullResult()
        in /var/www/src/CoreApiBundle/Repository/CellDetailsRepository.php line 19

[2] PDOException: SQLSTATE[HY000]: General error
    at n/a
        in /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 108

    at PDOStatement->fetch('2')
        in /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 108

    at Doctrine\DBAL\Driver\PDOStatement->fetch('2')
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 164

    at Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData()
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php line 147

    at Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(object(PDOStatement), object(ResultSetMappingBuilder), array())
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 978

    at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, null)
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 924

    at Doctrine\ORM\AbstractQuery->execute(null, null)
        in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 766

    at Doctrine\ORM\AbstractQuery->getOneOrNullResult()
        in /var/www/src/CoreApiBundle/Repository/CellDetailsRepository.php line 19

This result can be tested with this stored procedure:

BEGIN
if not exists(select null from tbl_cells limit 0) THEN
    SELECT NULL LIMIT 0;
end if;
END

Workaround:
To make this not show errors the stored procedure must do dummy selects in else statment
For example:

BEGIN
if exists( select something from some_tabel where something) than
    select a,b,c,d from  some_tabel where something
else
    SELECT NULL LIMIT 0;
end if;
END;
Originally created by @PlamenVasilev on GitHub (Sep 2, 2016). I have named query which calls stored procedure with one parameter. I call the stored procedure with ``` $query = $this->createNativeNamedQuery('CallStoredProcedure') ->setParameter('id', $id); return $query->getOneOrNullResult(); ``` the stored procedure is something like: ``` BEGIN if exists( select something from some_tabel where something) than select a,b,c,d from some_tabel where something end if; END; ``` When i have row in the table the result is returned and everything is fine. When there are now rows matched the stored procedure doesn't return anything and doctrine gives me `SQLSTATE[HY000]: General error` the full backtrace is: ``` [1] Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000]: General error at n/a in /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 117 at Doctrine\DBAL\Driver\PDOStatement->fetch('2') in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 164 at Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData() in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php line 147 at Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(object(PDOStatement), object(ResultSetMappingBuilder), array()) in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 978 at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, null) in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 924 at Doctrine\ORM\AbstractQuery->execute(null, null) in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 766 at Doctrine\ORM\AbstractQuery->getOneOrNullResult() in /var/www/src/CoreApiBundle/Repository/CellDetailsRepository.php line 19 [2] PDOException: SQLSTATE[HY000]: General error at n/a in /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 108 at PDOStatement->fetch('2') in /var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php line 108 at Doctrine\DBAL\Driver\PDOStatement->fetch('2') in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php line 164 at Doctrine\ORM\Internal\Hydration\ObjectHydrator->hydrateAllData() in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php line 147 at Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll(object(PDOStatement), object(ResultSetMappingBuilder), array()) in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 978 at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, null) in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 924 at Doctrine\ORM\AbstractQuery->execute(null, null) in /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 766 at Doctrine\ORM\AbstractQuery->getOneOrNullResult() in /var/www/src/CoreApiBundle/Repository/CellDetailsRepository.php line 19 ``` This result can be tested with this stored procedure: ``` BEGIN if not exists(select null from tbl_cells limit 0) THEN SELECT NULL LIMIT 0; end if; END ``` **Workaround:** To make this not show errors the stored procedure must do dummy selects in `else` statment For example: ``` BEGIN if exists( select something from some_tabel where something) than select a,b,c,d from some_tabel where something else SELECT NULL LIMIT 0; end if; END; ```
admin added the BugInvalidMissing Tests labels 2026-01-22 15:02:25 +01:00
Author
Owner

@Ocramius commented on GitHub (Sep 7, 2016):

@PlamenVasilev if I read this correctly, this is a PDOException being thrown by PDO itself, not by doctrine?

If you can confirm that, then this has to be escalated to a PDO bug, in my opinion ( at http://bugs.php.net/ ), and marked as "can't fix" here.

@Ocramius commented on GitHub (Sep 7, 2016): @PlamenVasilev if I read this correctly, this is a `PDOException` being thrown by PDO itself, not by doctrine? If you can confirm that, then this has to be escalated to a PDO bug, in my opinion ( at http://bugs.php.net/ ), and marked as "can't fix" here.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5239