-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBackend.py
34 lines (26 loc) · 1.21 KB
/
Backend.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
import sqlite3
class Database:
def __init__(self, db):
self.con = sqlite3.connect(db)
self.cur = self.con.cursor()
self.cur.execute("CREATE TABLE IF NOT EXISTS books (ID INTEGER PRIMARY KEY, TITLE TEXT, AUTHOR TEXT, YEAR INTEGER, ISBN INTEGER)")
self.con.commit()
def insert(self, title, author, year, isbn):
self.cur.execute("INSERT INTO BOOKS VALUES (NULL,?,?,?,?)",(title, author, year, isbn))
self.con.commit()
def view(self):
self.cur.execute("SELECT * FROM BOOKS")
rows = self.cur.fetchall()
return rows
def search(self, title="", author="", year="", isbn=""):
self.cur.execute("SELECT * FROM BOOKS WHERE TITLE=? OR AUTHOR=? OR YEAR=? OR ISBN=?", (title, author, year, isbn))
rows = self.cur.fetchall()
return rows
def delete(self, ID):
self.cur.execute("DELETE FROM BOOKS WHERE ID=?", (ID,))
self.con.commit()
def update(self, ID, title, author, year, isbn):
self.cur.execute("UPDATE BOOKS SET TITLE=?, AUTHOR=?, YEAR=?, ISBN=? WHERE ID=?", (title, author, year, isbn, ID))
self.con.commit()
def __del__(self):
self.con.close()