hi
i am creating a application i want to verify the user input name from my database.
These are my Two table
database function
Where i test the application it prints "record already exists" when it not exist inthe database.
i am creating a application i want to verify the user input name from my database.
These are my Two table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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() |
1 2 3 4 5 6 |
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" ) |
Gribouillis write Sep-10-2022, 05:31 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.