-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_fxns.py
43 lines (31 loc) · 1.28 KB
/
db_fxns.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
import sqlite3
conn = sqlite3.connect('data.db',check_same_thread=False)
c = conn.cursor()
def create_table():
c.execute('CREATE TABLE IF NOT EXISTS taskstable(task TEXT,task_status TEXT,task_due_date DATE)')
def add_data(task,task_status,task_due_date):
c.execute('INSERT INTO taskstable(task,task_status,task_due_date) VALUES (?,?,?)',(task,task_status,task_due_date))
conn.commit()
def view_all_data():
c.execute('SELECT * FROM taskstable')
data = c.fetchall()
return data
def view_all_task_names():
c.execute('SELECT DISTINCT task FROM taskstable')
data = c.fetchall()
return data
def get_task(task):
c.execute('SELECT * FROM taskstable WHERE task="{}"'.format(task))
data = c.fetchall()
return data
def get_task_by_status(task_status):
c.execute('SELECT * FROM taskstable WHERE task_status="{}"'.format(task_status))
data = c.fetchall()
def edit_task_data(new_task,new_task_status,new_task_date,task,task_status,task_due_date):
c.execute("UPDATE taskstable SET task =?,task_status=?,task_due_date=? WHERE task=? and task_status=? and task_due_date=? ",(new_task,new_task_status,new_task_date,task,task_status,task_due_date))
conn.commit()
data = c.fetchall()
return data
def delete_data(task):
c.execute('DELETE FROM taskstable WHERE task="{}"'.format(task))
conn.commit()