Sep-10-2022, 05:21 PM
hi
i am creating a application i want to verify the user input name from my database.
These are my Two table
i am creating a application i want to verify the user input name from my database.
These are my Two table
def create_tables(db): cur = db.cursor() cur.execute("""CREATE TABLE IF NOT EXISTS Habit ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, task_specification TEXT, period TEXT, created_at BOOLEAN, streak INT ) """) cur.execute("""CREATE TABLE IF NOT EXISTS count ( name TEXT, created_at BOOLEAN, FOREIGN KEY (name) REFERENCES Habit(name))""") db.commit()database function
def get_habit_data(db, name): cur = db.cursor() cur.execute("SELECT * FROM Habit WHERE name=?", (name,)) result = cur.fetchone() if result is None: print("record already exists")Where i test the application it prints "record already exists" when it not exist inthe database.