Mysql While Loop Exit Python Code Generator