Repository navigation
Expand file tree
/
Copy pathdatabase.py
More file actions
55 lines (49 loc) · 1.94 KB
/
Copy pathdatabase.py
File metadata and controls
55 lines (49 loc) · 1.94 KB
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
# To add any data you need two arguments name(string) and status of the task which by default is 0
# meaning that task is not yet completed (1 means it is completed)
# Update required 3 arguments which are old_name, new_name, task_status(0 or 1)
# data is stored in the form of task_name, task_status and current date
import sqlite3
class DataBase():
def __init__(self):
conn = sqlite3.connect("Task_data.db")
self.conn = conn
cur = conn.cursor()
self.cur = cur
cur.execute(
"""CREATE TABLE IF NOT EXISTS Task_data(
name TEXT,
status INTEGER,
date_added TEXT
)"""
)
conn.commit()
def return_data(self):
self.cur.execute("SELECT * FROM Task_data")
return self.cur.fetchall()
def add_data(self, name, status=0, current_date = 0):
try:
self.cur.execute(
"INSERT INTO Task_data (name, status, date_added) VALUES (?, ?, ?)",
(name, status, current_date),
)
self.conn.commit()
return True
except Exception as e:
return f"Error occurred while adding data: {e}: "
def update_data(self, name, new_name, status=0, current_date=0):
try:
self.cur.execute(
"UPDATE Task_data SET name=?, status=?, date_added=? WHERE name=?",
(new_name, status, current_date, name),
)
self.conn.commit()
return True
except Exception as e:
return f"Error occurred while updating data: {e}:"
def delete_data(self, name):
try:
self.cur.execute("DELETE FROM Task_data WHERE name=?", (name,))
self.conn.commit()
return True
except Exception as e:
return f"Error occurred while deleting data: {e}:"