'How do i check if a row exists in sqlite table?

I am trying to check if a row exist in an sqlite3 table in python. i want to check if there is an existing username in the table. my function is a class method here is my code method.

def usercheck(self,username):
    conn=sqlite3.connect(self.db)
    c=conn.cursor()
    try :
        user=c.execute("SELECT True FROM Users  WHERE Username= %s " %(username)).fetchone()
        if user != None:
            return True
        else :
            return False

    except sqlite3.OperationalError as e:
        print(' AN ERROR OCCURED')
        raise 
    conn.close() 

usercheck('admin')

But i get an error saying no such column

 user=c.execute("SELECT True FROM Users  WHERE Username= %s " %(username)).fetchone()
 sqlite3.OperationalError: no such column: admin

I have aslo tried it this way

user=c.execute("SELECT True FROM Users  WHERE Username= ? " (username)).fetchone()
        

I got a differet error code

TypeError: 'str' object is not callable


Solution 1:[1]

Try this

user=c.execute("SELECT True FROM Users  WHERE Username= %s ",(username,)).fetchone()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ashkan Goleh Pour