-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
52 lines (44 loc) · 1.33 KB
/
Copy pathdatabase.py
File metadata and controls
52 lines (44 loc) · 1.33 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
import sqlite3
import os
DEFAULT_PATH = os.path.join(
os.path.dirname(__file__), "database.sqlite3"
) # define dfilepath to be identical to folder
def createDB():
try:
con = db_connect() # connect to the database
cur = con.cursor() # initiate the obj cursor
cur.execute(
"""
CREATE TABLE IF NOT EXISTS worktime (
DATUM TEXT PRIMARY KEY,
VON TEXT,
BIS TEXT,
PAUSE TEXT,
ARBEITSZEIT TEXT,
UEBERSTUNDEN TEXT
)"""
)
cur.execute(
"""
CREATE TABLE IF NOT EXISTS settings (
NAME TEXT PRIMARY KEY,
VALUE INTEGER
)"""
)
cur.execute("SELECT * FROM settings WHERE NAME='workweekhours'")
entry = cur.fetchone()
if entry is None:
cur.execute(
"INSERT OR REPLACE INTO settings(NAME,VALUE) VALUES(?,?)",
("workweekhours", 35),
)
con.commit()
cur.close()
except sqlite3.Error as error:
print("Failed to create database", error)
finally:
if con:
con.close()
def db_connect(db_path=DEFAULT_PATH): # module to create hte db
con = sqlite3.connect(db_path)
return con