The problem is in your recursion. What happens is:
- You enter the function rebuild_tree.
- You create a statement handler, using prepare.
- You call execute on it.
- You fetch once.
- You go into recursion.
- You call execute on it.
- You fetch once.
- You go into recursion, etc.
- If there's nothing more to fetch, you return from
recursion.
- And then you fetch again, due to the while.
And it's this fetch that causes the problem. The corresponding execute has been cancelled because of the
execute you did in recursion.
Abigail