-
Hi, I have a piece of code that runs daily and was working fine up until today (no changes were made to it). I have a function on my Phalcon model for a DB table, let's call it TestEntries:
This returns a ResultSet/Simple with 35 entries.
I appreciate that my original query (looking for status 3) would now not yield any results as the entries have status 2. This code is NOT running in a db transaction begin/commit block. However, without any other code inbetween, I know have a second foreach loop through the ResultSet (which still reports a count of 35). It might seem poor coding to have to foreach loops of the same items after each other, but let us please not focus on that for the sake of the argument. In my second loop, I just add all the IDs to an array.
This fails. When I added a var_dump($test_entry) into the loop (instead of adding to array), it output 35 times bool(false). I guess what I am saying is, I understand what is failing, I just don't understand why it suddenly is! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I figured out the answer to my question. The key lies within this part:
As it turns out, the ResultSet logic changes when we have more than 32 results. However, if we get more than 32 results, none of them are fetched in the constructor, and instead they are fetched every time during the loop, hence why the second loop now fails. My previous, successful runs of the job had had around 25-30 results, only the last one, where it started failing, had 35. |
Beta Was this translation helpful? Give feedback.
-
In the online communities that I have discovered, the play snake provides users with helpful suggestions for how they might amuse themselves and discover new and exciting things. |
Beta Was this translation helpful? Give feedback.
I figured out the answer to my question.
The key lies within this part:
As it turns out, the ResultSet logic changes when we have more than 32 results.
We can see this in the ResultSet constructor - if the result count is 32 or less, all results are fetched at once and stored in the ResultSet, meaning we can loop through as often as we want.
However, if we get more than 32 results, none of them are fetched in the constructor, and instead they are fetched every time during the loop, hence why the second loop now fails.
My previous, successful runs of the job had had around 25-30 results, only the last one, where it started failing, had 35.