I have a few suggestions:<br> 1. Find a way to avoid using the count_changes pragma. It is deprecated.<br> 2. Reduce your scenario to a set of meta-commands and SQL statements that the CLI shell can run.<br> 3. Read the docs for the members of the step 2 set.<br> 4. Post here the minimal repro set of step 2 and remaining questions. Time ordering of operations will have an effect upon the outcome, and is not apparent in your post. So please consider my 4-step procedure to be a good way to clarify what you are doing, (if this proves necessary after doing step 3.)