-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlbackend.py
41 lines (34 loc) · 1.08 KB
/
sqlbackend.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
35
36
37
38
39
40
41
import sqlite3
"""General flow
1. Connect to database
2. Create cursor
3. Execute action
4. Commit changes
5. Close connection
"""
def create_table():
conn = sqlite3.connect("database.db")
cur = conn.cursor()
cur.execute("DROP TABLE IF EXISTS main")
cur.execute("CREATE TABLE IF NOT EXISTS main (query TEXT, pmc TEXT, doi TEXT, title TEXT, authors TEXT, date TEXT, abstract TEXT, images TEXT)")
conn.commit()
conn.close()
def insert(query, pmc, doi, title, authors, date, abstract, images):
conn = sqlite3.connect("database.db")
cur = conn.cursor()
cur.execute("INSERT INTO main VALUES (?, ?, ?, ?, ?, ?, ?, ?)", (query, pmc, doi, title, authors, date, abstract, images))
conn.commit()
conn.close()
def view():
conn = sqlite3.connect("database.db")
cur = conn.cursor()
cur.execute("SELECT * FROM main")
rows = cur.fetchall()
conn.close()
return rows
def delete(pmc):
conn = sqlite3.connect("database.db")
cur = conn.cursor()
cur.execute("DELETE FROM main WHERE pmc = ?", (pmc,))
conn.commit()
conn.close()