-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql bacteria database
81 lines (60 loc) · 2.19 KB
/
sql bacteria database
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import sqlite3
def Creating_Database():
conn = sqlite3.connect("master.db")
cursor = conn.cursor()
#sql = "CREATE TABLE CommonBacteria (Name text, Effects text, Kingdom text)"
#cursor.execute(sql)
#null, integer, real, text, blob are data types and storage classes you specify when creating your table and defining the columns
cursor.execute("""CREATE TABLE CommonBacteria (
Name text,
Effects text,
Kingdom text
)""")
cursor.execute("INSERT INTO CommonBacteria VALUES ('Unknown', 'Unknown', 'Unknown')")
conn.commit()
cursor.close()
def Add_Data():
conn = sqlite3.connect("master.db")
cursor = conn.cursor()
while True:
Name = input("CommonBacteria\'s Name:")
Effects = input("CommonBacteria\'s Effects:")
Kingdom = input("CommonBacteria\'s Kingdom:")
sql = "INSERT INTO CommonBacteria (Name, Effects, Kingdom) VALUES (:rName, :rEffects, :Kingdom)"
cursor.execute(sql, {'rName': Name, 'rEffects': Effects, 'rKingdom': Kingdom})
conn.commit() #this saves the data to the database
loopcontrol = input ("Add another Bacteria (yes/no)?: ")
if loopcontrol == 'no':
break
cursor.close()
def Fetch_Data():
conn = sqlite3.connect("master.db")
cursor = conn.connect()
sql = "SELECT * FROM CommonBacteria" # * means add all
results = cursor.execute(sql)
all_bacteria = results.fetchall()
for i in all_bacteria:
print(i)
conn.commit()
cursor.close()
def Update_Data():
conn = sqlite3.connect("master.db")
cursor = conn.cursor()
sql = "UPDATE CommonBacteria SET Bacteria = 'Propionibacterium acnes' WHERE Bacteria 'Cutibacterium acnes'"
cursor.execute(sql)
conn.commit()
cursor.close()
def Delete_Data():
conn = sqlite3
cursur = conn.cursor()
sql = "DELETE FROM CommonBacteria WHERE Name = 'aminovorans'"
cursor.execute(sql)
conn.commit()
cursor.close()
def main():
#Creating_Database()
Add_Data()
#Fetch_Data()
#Update_Data()
#Delete_Data()
main()