Home>

This time, I would like to get not the values ​​themselves from the cell, but True -if there is, and False -if not.

check_where_player= sql.execute(f"SELECT DISTINCT Player_1 FROM PvP WHERE Player_1=
                                 '{user_id}'").fetchone()
print(check_where_player)
if check_where_player is True:
       print("The answer is positive")
else:
       print("The answer is negative")

I honestly don't know if I did it right or not, I just started learning sqlite and saw this method somewhere, but it still doesn't work. I will be glad if you help.

Just if check_where_player: maybe?

andreymal2022-01-24 20:49:39

@andreymal, I'll check it out well.

ZYX2022-01-24 20:56:03

@andreymal, It really came up, thanks, it looks like I haven't figured out Python itself yet.

ZYX2022-01-24 20:59:09

If you need to determine the very fact of the presence of a record in the result returned by the query, then instead of SELECT ... use SELECT EXISTS (SELECT ...) AS presence. If the original query returns at least one record, then the one shown will return TRUE, otherwise FALSE. There is also a suspicion that such a check will work faster, because it will stop immediately when the first record of the set is found.

Akina2022-01-25 04:45:42