in the code I entered to select the user_id
if it will be, and to output True
- if it is, or False
- if there is nothing, but in the database after I added this user, it cannot be found by SELECT
and as return always enter False
def user_exists(self, user_id):
#ceck exist user or not in table
result = self.cur.execute("SELECT 'user_id' FROM 'users' WHERE 'user_id' == ? ",(user_id,))
print(result.fetchone())
return bool(len(result.fetchall()))
this is the cod in SQL table
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER UNIQUE
NOT NULL,
regim INTEGER NOT NULL,
Status INTEGER,
datereg INTEGER DEFAULT ( (DATETIME('now') ) )
);
CodePudding user response:
SELECT user_id FROM users WHERE user_id = "username etc"
you shouldn't use == in sql for matching