Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-214

Unable to use PDO::FETCH_CLASS with a call to fetch()

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-BETA2, 2.0.0-BETA3, 2.0.0-BETA4, 2.0.0-RC1-RC3, 2.0-RC4, 2.0-RC5, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.1, 2.1.1, 2.1.2, 2.1.3, 2.1.5, 2.1.6, 2.2-BETA1, 2.2-BETA2, 2.2-RC1/RC2, 2.2.0-RC3, 2.2, 2.2.1, 2.2.2, 2.3, 2.5
    • Fix Version/s: 2.3
    • Component/s: Drivers
    • Labels:
      None

      Description

      EDITED: 2nd attempt to describe this - first one was confusing.

      I don't understand why the setFetchMode() method of Doctrine\DBAL\Driver\PDOStatement drops any arguments passed to it. It means that PDO::FETCH_CLASS cannot be used with calls to fetch() and no warning is given until the point when the underlying \PDOStatement complains that no class has been specified.

        Activity

        Andy Leon created issue -
        Andy Leon made changes -
        Field Original Value New Value
        Description The fetch() method of Doctrine\DBAL\Statement does not accept any arguments. So trying to use fetch(PDO::FETCH_CLASS, 'ClassName') fails. But it doesn't fail until the fetch() method is called on the actual PDOStatement object - at which point it complains that a class name has not been given.

        There's probably a good reason for this, but I can't find any documentation as to why. It seems like it's intentional based on Doctrine\DBAL\Driver\PDOStatement, as the setFetchMode() function here does not pass on the arguments it receives.
        EDITED: 2nd attempt to describe this - first one was confusing.

        I don't understand why the setFetchMode() method of Doctrine\DBAL\Driver\PDOStatement drops any arguments passed to it. It means that PDO::FETCH_CLASS cannot be used with calls to fetch() and no warning is given until the point when the underlying \PDOStatement complains that no class has been specified.
        Hide
        Antoine Froger added a comment - - edited

        In Doctrine/DBAL/Statement.php the 2nd and 3rd arguments of setFetchMode are dropped too.

        Error message example when PDO::FETCH_CLASS is used as the first argument of setFetchMode:
        $stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'ClassName');
        display the error: PDOException: SQLSTATE[HY000]: General error: fetch mode requires the classname argument

        Show
        Antoine Froger added a comment - - edited In Doctrine/DBAL/Statement.php the 2nd and 3rd arguments of setFetchMode are dropped too. Error message example when PDO::FETCH_CLASS is used as the first argument of setFetchMode: $stmt->setFetchMode(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'ClassName'); display the error: PDOException: SQLSTATE [HY000] : General error: fetch mode requires the classname argument
        Hide
        Fabien Potencier added a comment -

        This regression was introduced here: https://github.com/doctrine/dbal/commit/f4acc79a3e91059a932d7a2d43309f6f8f65fa59

        It breaks some of my websites when upgrading DBAL. So, this is not an improvement but a regression bug.

        Show
        Fabien Potencier added a comment - This regression was introduced here: https://github.com/doctrine/dbal/commit/f4acc79a3e91059a932d7a2d43309f6f8f65fa59 It breaks some of my websites when upgrading DBAL. So, this is not an improvement but a regression bug.
        Hide
        Benjamin Eberlei added a comment -

        Yes, i have to change this again.

        The problem is its complex to support the 2nd/3rd arguments in the statement caching layer, i will just throw an exception for now and add an improvement ticket.

        Show
        Benjamin Eberlei added a comment - Yes, i have to change this again. The problem is its complex to support the 2nd/3rd arguments in the statement caching layer, i will just throw an exception for now and add an improvement ticket.
        Hide
        Benjamin Eberlei added a comment -

        Fixed

        Show
        Benjamin Eberlei added a comment - Fixed
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.2.3 [ 10210 ]
        Fix Version/s 2.3 [ 10184 ]
        Resolution Fixed [ 1 ]
        Show
        Benjamin Eberlei added a comment - https://github.com/doctrine/dbal/commit/d3930dcdb89cc818798c8f13e4126f76cf82ef8b
        Benjamin Eberlei made changes -
        Workflow jira [ 13401 ] jira-feedback2 [ 17790 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17790 ] jira-feedback3 [ 20145 ]
        Guilherme Blanco made changes -
        Fix Version/s 2.2.3 [ 10210 ]
        Guilherme Blanco made changes -
        Affects Version/s 2.5 [ 10523 ]
        Affects Version/s 2.0.9 [ 10168 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DBAL-214, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Andy Leon
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: