mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Problem with PDO DBlib (MSSQL, Sybase, FreeTDS) - nested fetches clear outer ones #5244
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @r0ssIV on GitHub (Sep 7, 2016).
There is a known issue with PDO DBLib nested pdo->prepare()->execute statements (they work differently from for e.x. MySQL). Issue is described here https://bugs.php.net/bug.php?id=65945, and the explanation from PHP team is the following
For some reason, in latest Doctrine 2.5 this issue fired up. See ObjectHydrator.php\hydrateAllData()
Sometimes for OneToOne associations $this->hydrateRowData() can cause nested calls to $this->_stmt->fetch which cause the outer results buffer cleared, so only part of the records are returned (like only the first record).
The solution for this problem is using fetchAll:
or using separate connections.
@Ocramius commented on GitHub (Sep 7, 2016):
a
fetchAllmay work there, but a functional test case is to be written to expose the issue, first.It is still problematic code though, as it denies lazy-hydration, should we switch to generators in future.
@salimimani commented on GitHub (Feb 21, 2019):
Hello,
In a project I'm working on, we have encountered the exact same issue.
As soon as hydrateAllData() fetches the first row, hydrateRowData() clears the buffered fetch, and proceeds to retrieve additional data with another query.
When we move on to the next iteration of the while loop, all has been cleared and we cannot collect the next rows. $row is set to false.
The workaround we used is the following :
First collect all result rows with fetchAll and store in $rows
Then replace the while loop with a foreach ($rows as $row)
==> I'm about to commit and make a pull request
My team is preparing a simple test case to reproduce the issue easily.
Meanwhile, here is the server config :