Ilia
Ilia

Reputation: 13

SQLite query returning false

So for my project I'm trying to have the user type something into a text box and if it's equal to what is stored in the database then it will tell them it's true. However at the moment even when the correct thing is input it will return false. This is the current code for the part that gets the answer, returns and compares it:

    def submit():
        answerA=entry_A.get()
        answerB=entry_B.get()
        answerC=entry_C.get()
        answerD=entry_D.get()
        answerE=entry_E.get()
        answerF=entry_F.get()
        print(answerA,", ",answerB,", ",answerC,", ",answerD,", ",answerE,", ",answerF)

        labelA=cursor.execute\
        ("select labelA from diagramLabels where diaName == 'plantCell'").fetchall()
        con.commit()
        if labelA == answerA:
            print("Answer A is correct")
        else:
            print("Answer A is false")

And this is the result it gives in Idle, along with what's in the database

Please tell me what I'm doing wrong.

Upvotes: 1

Views: 433

Answers (1)

ColdIV
ColdIV

Reputation: 1104

You should use fetchone() instead of fetchall().
fetchall() returns a number of rows (like this: (('nucleus',),) ) whereas fetchone() will only return one row. You will then get something like this: ('nucleus',)
You can compare it with labelA[0] == answerA then.

Upvotes: 1

Related Questions