Insert into the same table inside the filtered range of a FindSet loop can cause infinite loops #733
christophstuber
started this conversation in
New Rule
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sorry for the title :)
This might be more of an edge case, but has happened to me personally.
Consider the following example:
The table MyTable has a field Status, which differentiates "New" from "Old" records. For each record, the "Value" is recalculated, saved into a new record and the previous version is set to "Old". The problem is, that depending on the key, the newly inserted records come after the initially found records and are therefore found by the Next(). This causes an infinite loop.
The easiest solution is to first save the found records to a temporary buffer, because that is not influenced by the inserts.
Therefore there should be a warning, if the Insert method is used inside a FindSet loop, where both the records used for FindSet and Insert are the same table and both of them are not temporary.
Beta Was this translation helpful? Give feedback.
All reactions