delete functionality
This commit is contained in:
18
database.py
18
database.py
@@ -12,12 +12,13 @@ cur.execute("CREATE TABLE IF NOT EXISTS USERS (id INTEGER PRIMARY KEY, name STRI
|
|||||||
|
|
||||||
# declare and insert some initial values
|
# declare and insert some initial values
|
||||||
timestamp_list = [
|
timestamp_list = [
|
||||||
(1, '1pm', 'null', 'Mikayla', 'work on project'),
|
('Mikayla', 'work on project'),
|
||||||
(2, '9pm', '11pm', 'not Mikayla', 'work on project'),
|
('not Mikayla', 'work on project'),
|
||||||
(3, '8am', '5pm', 'someone else', 'debugging')
|
('someone else', 'debugging')
|
||||||
]
|
]
|
||||||
|
|
||||||
cur.executemany("INSERT INTO TIMESTAMPS VALUES (?, ?, ?, ?, ?)", timestamp_list)
|
cur.executemany("INSERT INTO TIMESTAMPS (name, purpose) VALUES (?, ?)", timestamp_list)
|
||||||
|
con.commit()
|
||||||
|
|
||||||
# Functions to define:
|
# Functions to define:
|
||||||
# 1) Select all timestamps
|
# 1) Select all timestamps
|
||||||
@@ -26,8 +27,9 @@ cur.executemany("INSERT INTO TIMESTAMPS VALUES (?, ?, ?, ?, ?)", timestamp_list)
|
|||||||
# 4) Calculate complete sum of hours
|
# 4) Calculate complete sum of hours
|
||||||
|
|
||||||
def create_new_stamp(timestamp, name, purpose):
|
def create_new_stamp(timestamp, name, purpose):
|
||||||
to_insert = (999, timestamp, 'null', name, purpose)
|
to_insert = (timestamp, name, purpose)
|
||||||
cur.execute("INSERT INTO TIMESTAMPS VALUES (?, ?, ?, ?, ?)", to_insert)
|
cur.execute("INSERT INTO TIMESTAMPS (time_in, name, purpose) VALUES (?, ?, ?)", to_insert)
|
||||||
|
con.commit()
|
||||||
|
|
||||||
def get_all_stamps():
|
def get_all_stamps():
|
||||||
return cur.execute("SELECT * FROM TIMESTAMPS;")
|
return cur.execute("SELECT * FROM TIMESTAMPS;")
|
||||||
@@ -56,3 +58,7 @@ def get_weekly_hours():
|
|||||||
|
|
||||||
def get_all_hours():
|
def get_all_hours():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def delete_all_rows():
|
||||||
|
cur.executemany("DELETE * FROM TIMESTAMPS;")
|
||||||
BIN
db_util/data.db
BIN
db_util/data.db
Binary file not shown.
@@ -10,6 +10,7 @@ Please choose from the following options:
|
|||||||
3) Find a timestamp by date range
|
3) Find a timestamp by date range
|
||||||
4) Calculate total hours for the week
|
4) Calculate total hours for the week
|
||||||
5) Calculate complete sum of hours
|
5) Calculate complete sum of hours
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Inner functions detailed below:
|
# Inner functions detailed below:
|
||||||
@@ -100,6 +101,33 @@ def handle_second_option():
|
|||||||
def handle_third_option():
|
def handle_third_option():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __admin__():
|
||||||
|
print("ADMIN PORTAL")
|
||||||
|
print("Choose from additional actions below:")
|
||||||
|
print("""
|
||||||
|
1) Delete all rows from table (table and schema will persist)
|
||||||
|
2) Drop table (database will reinitialize on next render)
|
||||||
|
3) Backup data from SQLite file.
|
||||||
|
|
||||||
|
Take care, some actions will permanently delete all data.\n
|
||||||
|
""")
|
||||||
|
admin_prompt = input("Your response: ")
|
||||||
|
|
||||||
|
if int(admin_prompt) == 1:
|
||||||
|
print("Deleting all rows...")
|
||||||
|
delete_all_rows()
|
||||||
|
print("All rows deleted. Returning...")
|
||||||
|
parse_input()
|
||||||
|
elif int(admin_prompt) == 2:
|
||||||
|
print("Drop table. Confirm?")
|
||||||
|
elif int(admin_prompt) == 3:
|
||||||
|
print("Back up all SQLite data.")
|
||||||
|
else:
|
||||||
|
print("Invalid input.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Dialogue tree for top-level path handling
|
||||||
|
|
||||||
def parse_input():
|
def parse_input():
|
||||||
print(user_prompt)
|
print(user_prompt)
|
||||||
@@ -130,6 +158,8 @@ def parse_input():
|
|||||||
pass
|
pass
|
||||||
elif response == 4:
|
elif response == 4:
|
||||||
pass
|
pass
|
||||||
|
elif response == 871:
|
||||||
|
__admin__()
|
||||||
else:
|
else:
|
||||||
print("Please provide a valid selection.")
|
print("Please provide a valid selection.")
|
||||||
parse_input()
|
parse_input()
|
||||||
Reference in New Issue
Block a user