The first result is being skipped when executing the query from a Python code.
rooms = cur2.execute("SELECT r.* FROM rooms r JOIN room_members rm ON r.id = rm.room_id JOIN users u ON u.id = rm.user_id WHERE u.username = ?;",(usr,)).fetchall()
I want to get all the rooms that this usr is part of, the room_members playing many-to-many relationship, but for some reason if the result is one room it returns None the rooms var is empty and if the rooms is more then one it skips the first one and return the others. but if I run the query on the SQL shell it works fine and show the right results.
I hope I’m describing this well.
This could be due to how the fetchall()
result is processed, or there might be an issue with how the database connection or cursor is handled. so I tried fetchone()
, removing sqlite3.Row
, ensuring the consistency of Data Types, changing the cursor to
rooms = cur.execute('''
SELECT r.*
FROM rooms r
JOIN room_members rm ON r.id = rm.room_id
JOIN users u ON u.id = rm.user_id
WHERE u.username = ?;
''', (usr,)).fetchall()
I can’t figure what causes this problem.
2