-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork_database.py
88 lines (61 loc) · 1.92 KB
/
work_database.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import psycopg2
import dbconinfo
def dbconnectexp():
db = psycopg2.connect(
host = "localhost",
database = dbconinfo.dbname,
user = "postgres",
password = "goldcoin",
port = dbconinfo.portname,
)
c = db.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS work(id serial primary key, expense_name TEXT, discription TEXT)''')
db.commit()
db.close()
def dbentryexp(name, discriprion):
db = psycopg2.connect(
host = "localhost",
database = dbconinfo.dbname,
user = "postgres",
password = "goldcoin",
port = dbconinfo.portname,
)
c = db.cursor()
c.execute('''INSERT INTO work(expense_name, discription) VALUES(%s, %s)''', (name, discriprion))
db.commit()
db.close()
def dbupdatexp(expense_name, discription, id):
db = psycopg2.connect(
host = "localhost",
database = dbconinfo.dbname,
user = "postgres",
password = "goldcoin",
port = dbconinfo.portname,
)
c = db.cursor()
c.execute('''UPDATE work SET expense_name = %s, discription = %s WHERE id = %s''', (expense_name, discription, id))
db.commit()
db.close()
def dbdeleteexp(id):
db = psycopg2.connect(
host = "localhost",
database = dbconinfo.dbname,
user = "postgres",
password = "goldcoin",
port = dbconinfo.portname,
)
c = db.cursor()
c.execute('''DELETE FROM work WHERE id=''' + id)
db.commit()
db.close()
def dbfetchexp():
db = psycopg2.connect(
host = "localhost",
database = dbconinfo.dbname,
user = "postgres",
password = "goldcoin",
port = dbconinfo.portname,
)
c = db.cursor()
c.execute('''SELECT * FROM public.work''')
return c