forked from tanmay2298/Code_Fun_Do_PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_module.py
31 lines (27 loc) · 905 Bytes
/
database_module.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
import sqlite3
from datetime import datetime
def create_table():
conn = sqlite3.connect("Database.db")
cur = conn.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS Database(ID INTEGER PRIMARY KEY, Entry_Time timestamp, Exit_Time timestamp)")
conn.commit()
conn.close()
def insert_data(Entry_Time, Exit_Time):
conn = sqlite3.connect("Database.db")
cur = conn.cursor()
cur.execute("INSERT INTO Database VALUES (NULL, ?, ?)", (Entry_Time, Exit_Time))
conn.commit()
conn.close()
def update(id, Entry_Time, Exit_Time):
conn = sqlite3.connect("Database.db")
cur = conn.cursor()
cur.execute("UPDATE Database SET Entry_Time = ?, Exit_Time = ? where id = ?", (Entry_Time, Exit_Time, id))
conn.commit()
conn.close()
def get_id():
conn = sqlite3.connect("Database.db")
cur = conn.cursor()
cur.execute("SELECT max(id) as id FROM Database")
rows = cur.fetchall()
conn.close()
return rows[0][0]