-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.py
More file actions
65 lines (49 loc) · 1.52 KB
/
Copy pathbackend.py
File metadata and controls
65 lines (49 loc) · 1.52 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
60
61
62
63
64
65
import sqlite3
def connect():
#connection object
conn=sqlite3.connect("book.db")
#curser object
cur=conn.cursor()
#execute sql statement
cur.execute("CREATE TABLE IF NOT EXISTS book(id INTEGER PRIMARY KEY, title text, author text, year INTEGER, isbn INTEGER)")
conn.commit()
conn.close()
#add entry
def add(title,author, year,isbn):
conn=sqlite3.connect("book.db")
cur=conn.cursor()
cur.execute("INSERT INTO book VALUES(NULL,?,?,?,?)",(title,author, year,isbn))
conn.commit()
conn.close()
def view():
conn=sqlite3.connect("book.db")
cur=conn.cursor()
cur.execute("SELECT * from book")
rows=cur.fetchall()
conn.close()
return rows
def search(title="",author="", year="", isbn=""):
conn=sqlite3.connect("book.db")
cur=conn.cursor()
cur.execute("SELECT * from book WHERE title=? OR author=? OR year=? or isbn=?",(title,author, year, isbn))
rows=cur.fetchall()
conn.close()
return rows
def delete(id):
conn=sqlite3.connect("book.db")
cur=conn.cursor()
cur.execute("DELETE FROM book WHERE id=?",(id,))
conn.commit()
conn.close()
def update(id,title,author,year,isbn):
conn=sqlite3.connect("book.db")
cur=conn.cursor()
cur.execute("Update book SET title=?,author=?,year=?,isbn=? where id=?",(title,author,year,isbn,id))
conn.commit()
conn.close()
connect()
#insert("the sea", "John Tablet", 1918,91312132)
#insert("the earth", "Jina Smith", 1921,58312132)
delete(3)
view()
print(search(author="John Tablet"))