1

As I discovered in another question, loading 300k rows as entities with Doctrine is not a good idea and will consume at least a gigabyte of memory.

Since I needed some bitwise operations anyway, I figured I'd use a NativeQuery and iterate() over the result. However, after the first row, my value is always empty. My code is highly similar to the documentation:

$sql = "SELECT `pushToken` FROM `Devices`";
$rsm = new Doctrine\ORM\Query\ResultSetMappingBuilder(self::$entityManager);
$rsm->addScalarResult("pushToken", "pt");
$query = self::$entityManager->createNativeQuery($sql, $rsm);
$iterableDevices = $query->iterate();
foreach ($iterableDevices as $row)
{
    $message->addRecipient($row[0]["pt"]);
}

When I var_dump'ed $row however, I noticed that the index is actually incremented each time the code runs through the loop. This is contradicting the documentation. Am I doing something wrong, or have I discovered an honest mistake?

Community
  • 1
  • 1
Zsub
  • 1,799
  • 2
  • 15
  • 28
  • Have you tried iterating using the while-loop based approach shown in the second to last example on that manual page? I used that one, although with a DQL query, which worked just fine. – Jani Hartikainen May 27 '12 at 09:52
  • Yes, I just tested it and it gives the same 'strange' result. – Zsub May 27 '12 at 14:17

1 Answers1

0

I found solution here Merge all sub arrays into one and did like that:

$iterator = $this->getEntityManager()->createNativeQuery($sql, $rsm)->iterate();
foreach ($iterator as $row) {
    yield call_user_func_array('array_merge', $row);
}