-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_Invent.py
More file actions
59 lines (45 loc) · 1.82 KB
/
Copy pathdb_Invent.py
File metadata and controls
59 lines (45 loc) · 1.82 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
53
54
55
56
57
58
59
import sqlite3
class Database:
"""docstring for Database"""
def __init__(self, db):
self.conn = sqlite3.connect(db)
self.cur = self.conn.cursor()
self.cur.execute(
"CREATE TABLE IF NOT EXISTS items(id INTEGER PRIMARY KEY, item text, quantity text, "
"description text, price text)")
self.conn.commit()
def fetch(self):
self.cur.execute("SELECT * FROM items")
rows = self.cur.fetchall()
return rows
def insert(self, item, quantity, description, price):
self.cur.execute("INSERT INTO items VALUES(NULL, ?, ?, ?, ?)", (item, quantity, description, price))
self.conn.commit()
def remove(self, id):
self.cur.execute("DELETE FROM items WHERE id=?", (id,))
self.conn.commit()
def update(self, id, item, quantity, description, price):
self.cur.execute("UPDATE items SET item=?, quantity=?, description=?, price=? WHERE id=?",
(item, quantity, description, price, id))
self.conn.commit()
def __del__(self):
self.conn.close()
class Data:
def __init__(self, db):
self.conn = sqlite3.connect(db)
self.cur = self.conn.cursor()
self.cur.execute(
"CREATE TABLE IF NOT EXISTS counts(id INTEGER PRIMARY KEY, count text)")
self.conn.commit()
def fetch(self):
self.cur.execute("SELECT * FROM counts")
rows = self.cur.fetchall()
return rows
def insert(self, count):
self.cur.execute("INSERT INTO counts VALUES(NULL, ?)", count,)
self.conn.commit()
def update(self, id, count):
self.cur.execute("UPDATE counts SET count=? WHERE id=?", count,)
self.conn.commit()
def __del__(self):
self.conn.close()