-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.py
27 lines (21 loc) · 904 Bytes
/
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
import sqlite3
class db:
def __init__(self):
self.conn = sqlite3.connect("books.db")
self.cur = self.conn.cursor()
self.cur.execute("CREATE TABLE IF NOT EXISTS book (id INTEGER PRIMARY KEY, title TEXT, author TEXT, year INTEGER, isbn INTEGER)")
self.conn.commit()
def insert(self,title, author, year, isbn):
self.cur.execute("INSERT INTO book VALUES(NULL,?,?,?,?)", (title,author,year,isbn))
self.conn.commit()
def view(self):
self.cur.execute("SELECT * FROM book")
rows = self.cur.fetchall()
return rows
def search(self,title="", author="", year="", isbn=""):
self.cur.execute("SELECT * FROM book WHERE title = ? OR author = ? OR year = ? OR isbn = ?", (title, author, year, isbn))
rows = self.cur.fetchall()
return rows
#destructor
def __del__(self):
self.conn.close()