-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathModel.py
More file actions
34 lines (28 loc) · 1.11 KB
/
Model.py
File metadata and controls
34 lines (28 loc) · 1.11 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
import sqlite3
from src import Constants
class Model:
def __init__(self):
self.con = sqlite3.connect(Constants.DATABASE_NAME)
self.cur = self.con.cursor()
def addToTable(self, title, author):
self.values = (str(title), str(author))
self.cur.execute("INSERT INTO Books (title, author) values (?,?)", self.values)
print(self.cur.fetchall())
self.con.commit()
def updateTable(self, id, title, author):
self.values = (str(title), str(author), int(id))
self.cur.execute("UPDATE Books SET title = ?, author= ? WHERE id = ?", self.values)
print("Updated: ", self.cur.fetchall())
self.con.commit()
def deleteDataFromTable(self, id):
self.values = (int(id),)
print("TYPE: ", type(int(id)), "value: ", int(id))
self.cur.execute("DELETE FROM Books WHERE id = ?", self.values)
print(self.cur.fetchall())
self.con.commit()
def getAllData(self):
self.cur.execute("SELECT * FROM Books")
result = self.cur.fetchall()
print(result)
self.con.commit()
return result