K
K
Kir Mozor2020-12-06 08:19:13
Python
Kir Mozor, 2020-12-06 08:19:13

SQLite3 Problem with conditions?

I wrote a code that should select the data of the id line in SQLite3, if in the line game_is_true = True and game_is_true2 = False and display them on the screen. In the database, the table users contains the following lines
id game_id game_is_true game_is_true2
543,535,345 54,353,467,546 True False
85,648,444 7,678,575,484 False False
675,785,757 76,745,785 True True
87,768,686,767 856,757,445 False True
1 line of code fit condition, but no lines are not displayed, just []. What's wrong with the code?

# -*- coding: utf-8 -*-

import sqlite3
 
conn = sqlite3.connect("mydatabase0.db")
cursor = conn.cursor()
 
cursor.execute("""CREATE TABLE IF NOT EXISTS users (
                  id BIGINT,
                  game_id BIGINT,
                  game_is_true TEXT,
                  game_is_true2 TEXT
               )""")
conn.commit()
sqla = [('543535345', '54353467546', 'True', 'False'),
          ('85648444', '7678575484', 'False', 'False'),
          ('675785757', '76745785', 'True', 'True'),
          ('87768686767', '856757445', 'False', 'True')]
cursor.executemany('INSERT INTO users VALUES (?, ?, ?, ?)', sqla)
conn.commit()

cursor.execute("""SELECT id FROM users WHERE game_is_true = True AND game_is_true = False""")
conn.commit
print(cursor.fetchall()) # or use fetchone()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-12-06
@150_Kirill_150

Your fields game_is_true and game_is_true2 are text fields, so you need to pass strings to the condition, not boolean values.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question