|
| 1 | +# Importing the module |
| 2 | +import sqlite3 |
| 3 | + |
| 4 | +# Writing the Query for creating the exercise table |
| 5 | +Create_exercise_table = """ |
| 6 | + CREATE TABLE IF NOT EXISTS exercise |
| 7 | + ( |
| 8 | + id INTEGER PRIMARY KEY, |
| 9 | + date TEXT, |
| 10 | + data TEXT |
| 11 | + ); |
| 12 | + """ |
| 13 | + |
| 14 | +# Writing the query for inserting values into exercise table |
| 15 | +insert_exercise = """ |
| 16 | + INSERT INTO exercise (date, data) VALUES (?, ?); |
| 17 | +""" |
| 18 | + |
| 19 | +# Writing the query for inserting values into food table |
| 20 | +insert_food = """ |
| 21 | + INSERT INTO food (date, data) VALUES (?, ?); |
| 22 | +""" |
| 23 | + |
| 24 | +# Writing the query for creating the food table |
| 25 | +Create_food_table = """ |
| 26 | + CREATE TABLE IF NOT EXISTS food |
| 27 | + ( |
| 28 | + id INTEGER PRIMARY KEY, |
| 29 | + date TEXT, |
| 30 | + data TEXT |
| 31 | + ); |
| 32 | + """ |
| 33 | + |
| 34 | +# Writing the query for deleting the exercise table |
| 35 | +delete_exercise_table = """ |
| 36 | + DROP TABLE exercise |
| 37 | + """ |
| 38 | + |
| 39 | +# Writing the query for deleting the food table |
| 40 | +delete_food_table = """ |
| 41 | + DROP TABLE food |
| 42 | + """ |
| 43 | + |
| 44 | +# defining functions for different queries |
| 45 | + |
| 46 | +def connect(): |
| 47 | + connection = sqlite3.connect("data.db") |
| 48 | + return connection |
| 49 | + |
| 50 | + |
| 51 | +def create_table1(connection): |
| 52 | + with connection: |
| 53 | + connection.execute(Create_exercise_table) |
| 54 | + |
| 55 | + |
| 56 | +def create_table2(connection): |
| 57 | + with connection: |
| 58 | + connection.execute(Create_food_table) |
| 59 | + |
| 60 | + |
| 61 | +def add_exercise(connection, date, data): |
| 62 | + with connection: |
| 63 | + connection.execute(insert_exercise, (date, data)) |
| 64 | + |
| 65 | + |
| 66 | +def add_food(connection, date, data): |
| 67 | + with connection: |
| 68 | + connection.execute(insert_food, (date, data)) |
| 69 | + |
| 70 | + |
| 71 | +def delete_exercise(connection): |
| 72 | + with connection: |
| 73 | + connection.execute(delete_exercise_table) |
| 74 | + |
| 75 | + |
| 76 | +def delete_food(connection): |
| 77 | + with connection: |
| 78 | + connection.execute(delete_food_table) |
0 commit comments