"index" always 0 cause the first if-clause statement always false and incorrect sql statement.
Bug resolved: Initializing index to 0 inside the loop Previously, the index variable was incorrectly initialised to 0 for every iteration of the loop, causing the if-clause (index != 0) to always evaluate to False. This resulted in undesired behaviour. Now, the bug has been fixed by moving the initialisation of index inside the loop, ensuring that it starts at 0 for each iteration. The if-clause will now correctly evaluate based on the updated value of index, resolving the issue.