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