-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabour_purchase_database.py
86 lines (61 loc) · 2.62 KB
/
labour_purchase_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
import psycopg2
import dbconinfo
def dbconnect():
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 labor_purchase1(id serial primary key, date_and_time TEXT,customer_name TEXT, customer_id TEXT, supplier_name TEXT, supplier_id TEXT, inventory_name TEXT, inv_id TEXT, qty INT, price INT, total INT)''')
db.commit()
db.close()
def dbentry(date, customer_name, customer_id, supplier_name, supplier_id, inventory_name, inv_id, qty, price, total):
db = psycopg2.connect(
host = "localhost",
database = dbconinfo.dbname,
user = "postgres",
password = "goldcoin",
port = dbconinfo.portname,
)
c = db.cursor()
c.execute('''INSERT INTO labor_purchase1(date_and_time, customer_name, customer_id, supplier_name, supplier_id, inventory_name, inv_id, qty, price, total) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)''', (date, customer_name, customer_id, supplier_name, supplier_id, inventory_name, inv_id, qty, price, total))
db.commit()
db.close()
def dbupdate(date, customer_name, customer_id, supplier_name, supplier_id, inventory_name, inv_id, qty, price, total, id):
db = psycopg2.connect(
host = "localhost",
database = dbconinfo.dbname,
user = "postgres",
password = "goldcoin",
port = dbconinfo.portname,
)
c = db.cursor()
c.execute('''UPDATE labor_purchase1 SET date_and_time = %s,customer_name= %s, customer_id= %s, supplier_name= %s, supplier_id= %s, inventory_name= %s, inv_id= %s, qty= %s, price= %s, total= %s WHERE id = %s''', (date, customer_name, customer_id, supplier_name, supplier_id, inventory_name, inv_id, qty, price, total, id))
db.commit()
db.close()
def dbdelete(id):
db = psycopg2.connect(
host = "localhost",
database = dbconinfo.dbname,
user = "postgres",
password = "goldcoin",
port = dbconinfo.portname,
)
c = db.cursor()
c.execute('''DELETE FROM labor_purchase1 WHERE id=''' + id)
db.commit()
db.close()
def dbfetch():
db = psycopg2.connect(
host = "localhost",
database = dbconinfo.dbname,
user = "postgres",
password = "goldcoin",
port = dbconinfo.portname,
)
c = db.cursor()
c.execute('''SELECT * FROM public.labor_purchase1''')
return c