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

Missing parameter fetchArgument for fetch and fetchAll methods #3066

Closed
akrz opened this issue Mar 22, 2018 · 9 comments
Closed

Missing parameter fetchArgument for fetch and fetchAll methods #3066

akrz opened this issue Mar 22, 2018 · 9 comments

Comments

@akrz
Copy link

akrz commented Mar 22, 2018

If I want to fetch a record and I want to use PDO::FETCH_CLASS, I can't do

$example = $qb->execute()->fetch(\PDO::FETCH_CLASS, Example::class);

because the method signature only has one parameter:

# Doctrine\DBAL\Statement
public function fetch($fetchMode = null) {...}

The fetchAll method actually has a second parameter in the signature to assign an argument

# Doctrine\DBAL\Statement
public function fetchAll($fetchMode = null, $fetchArgument = 0) {...}

But the Interface only has one parameter:

# Doctrine\DBAL\Driver\ResultStatement
public function fetchAll($fetchMode = null);

So it throws an annoying warning when I want to use

$example = $qb->execute()->fetchAll(\PDO::FETCH_CLASS, Example::class);

The workaround is setting the fetch mode and then do a fetch/fetchAll but it should be possible to pass an argument directly to those methods.

$stmt = $qb->execute();
$stmt->setFetchMode(\PDO::FETCH_CLASS, Example::class);
$example = $stmt->fetch();
@Ocramius
Copy link
Member

@morozov @deeky666 we should really really really disallow the \PDO::FETCH_CLASS abomination.

@akrz
Copy link
Author

akrz commented Mar 22, 2018

@Ocramius Can I ask why?

@Ocramius
Copy link
Member

@akrz it sets property fields with something inconsistent with reflection behavior, and creates instances by skipping ctor calls as well. If you really want to go in that direction, then you want to use a standard hydrator and avoid the bugs/quirks of PDO, by using something built in userland: even if slower, it is not worth the pain to go with the PDO internals here.

@morozov
Copy link
Member

morozov commented Mar 22, 2018

Please see #2958 (comment) for more details.

@morozov
Copy link
Member

morozov commented Mar 22, 2018

I'd remove it together with $columnIndex for FETCH_COLUMN and drop ...$args entirely.

@deeky666
Copy link
Member

Not to mention all of those non-PDO drivers not/rarely supporting Class/Object hydration natively. We are currently doing basic "userland" hydration for those drivers just to keep compatibility with our driver API. This is something that should be done outside of DBAL. I wish we could get rid of fetch modes completely and simply provide associative arrays as results and leave everything else for other libraries/userland...

@mihas2
Copy link

mihas2 commented Mar 30, 2018

And $cursorOrientation not support, and the "prepare" method does not support the settings of the scrollable cursor

    /**
     * {@inheritdoc}
     */
    public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
    {
        return $this->stmt->fetch($fetchMode);
    }

@morozov
Copy link
Member

morozov commented Jul 26, 2021

Closing as the API is no longer supported. See #3070.

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants