My database system uses a search function and since I updated it to search for multiple search terms it has stopped working. Can someone please explain why this isn’t working or correct the code?
Here is the code:
import sqlite3
from replit import clear
import time as t
def main():
bd = sqlite3.connect('Builds.db')
cursor = bd.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS Builds (
Build TEXT,
Weapon TEXT,
Aspect TEXT,
Keepsake1 TEXT,
Keepsake2 TEXT,
Keepsake3 TEXT,
Keepsake4 TEXT,
Arcana TEXT,
God1 TEXT,
God2 TEXT,
God3 TEXT,
Boon1 TEXT,
Boon2 TEXT,
Boon3 TEXT,
Hammer1 TEXT,
Hammer2 TEXT,
Hammer3 TEXT
)
''')
data = [
('Build Name', 'Weapon', 'Aspect', 'Keepsake1', 'Keepsake2', 'Keepsake3', 'Keepsake4', 'Arcana', 'God1', 'God2', 'God3', 'Boon1', 'Boon2', 'Boon3', 'Hammer1', 'Hammer2', 'Hammer3'),
('Pan Snipe', 'Sister Blades', 'Aspect of Pan',
'Transcendant Embryo', 'Aromatic Phial','Concave Stone', 'Knuckle Bones', 'None', 'Poseidon', 'Hera', 'Artemis', 'Wave Flourish', 'Engangment Ring', 'Death Warrant', 'Spiral Knives', 'Dancing Knives', 'None'),
('Speedrunners Favourite', 'Witchs Staff', 'Aspect of Momus', 'Iridescant Fan', 'Keepsake2', 'Keepsake3', 'Keepsake4', 'The Huntress (III), The Furies (VI)', 'Hera', 'Hephaestus', 'God3', 'Sworn Flourish', 'Boon2', 'Boon3', 'Double Moonshot', 'Shimmering Moonshot', 'Hammer3'),
]
cursor.executemany(
'INSERT INTO Builds (Build, Weapon, Aspect, Keepsake1, Keepsake2, Keepsake3, Keepsake4, Arcana, God1, God2, God3, Boon1, Boon2, Boon3, Hammer1, Hammer2, Hammer3) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
data)
while True:
clear()
selection = input("""
1) View list of builds
2) Add to build list
3) Search for build
4) Delete build from build list
5) Quit
Enter your selection: """)
if selection == "1":
cursor.execute('SELECT * FROM Builds')
for Build,Weapon,Aspect,Keepsake1,Keepsake2,Keepsake3,Keepsake4,Arcana,God1,God2,God3,Boon1,Boon2,Boon3,Hammer1,Hammer2,Hammer3 in cursor.fetchall():
clear()
print(f"""
Build name: {Build}
Weapon: {Weapon}
Aspect: {Aspect}
Keepsakes: {Keepsake1} for Erebus, {Keepsake2} for Oceanus, {Keepsake3} for Fields of Mourning and {Keepsake4} for Tartarus
Arcana Cards: {Arcana}
Gods: {God1}, {God2} and {God3}
Boons: {Boon1}, {Boon2} and {Boon3}
Hammers: {Hammer1}, {Hammer2} and {Hammer3}
""")
x = input("To go onto the next build press enter: ")
elif selection == "2":
build_name = input("Build name: ")
weapon = input("Enter Weapon: ")
aspect = input("Enter Aspect: ")
keepsake1 = input("Enter Keepsake for Erebus: ")
keepsake2 = input("Enter Keepsake for Oceanus: ")
keepsake3 = input("Enter Keepsake for Fields of Mourning: ")
keepsake4 = input("Enter Keepsake for Tartarus: ")
arcana = input("Enter Arcana: ")
god1 = input("Enter the most important god: ")
god2 = input("Enter the second most important god: ")
god3 = input("Enter the third most important god: ")
boon1 = input("Enter Boon 1: ")
boon2 = input("Enter Boon 2: ")
boon3 = input("Enter Boon 3: ")
hammer1 = input("Enter Hammer 1: ")
hammer2 = input("Enter Hammer 2:")
hammer3 = input("Enter Hammer 3: ")
print()
new_data = (build_name, weapon, aspect, keepsake1, keepsake2, keepsake3, keepsake4, arcana, god1, god2, god3, boon1, boon2, boon3, hammer1, hammer2, hammer3)
cursor.execute('INSERT INTO Builds (Build, Weapon, Aspect, Keepsake1, Keepsake2, Keepsake3, Keepsake4, Arcana, God1, God2, God3, Boon1, Hammer1) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', new_data)
bd.commit()
elif selection == "3":
clear()
search_part = input("""
Which part of the build would you like to search for?
1) Build name
2) Weapon
3) Aspect
4) Keepsakes
5) Arcana
6) Boons
7) Hammers
Enter your selection: """)
search_term = input("What do you want to search for?: ")
print()
if search_part == "1":
cursor.execute('SELECT * FROM Builds WHERE Build = ?', (search_term,))
if search_part == "2":
cursor.execute('SELECT * FROM Builds WHERE Weapon = ?', (search_term,))
if search_part == "3":
cursor.execute('SELECT * FROM Builds WHERE Aspect = ?', (search_term,))
if search_part == "4":
cursor.execute('SELECT * FROM Builds WHERE Keepsake1 = ?', (search_term,))
cursor.execute('SELECT * FROM Builds WHERE Keepsake2 = ?', (search_term,))
cursor.execute('SELECT * FROM Builds WHERE Keepsake3 = ?', (search_term,))
cursor.execute('SELECT * FROM Builds WHERE Keepsake4 = ?', (search_term,))
if search_part == "5":
cursor.execute('SELECT * FROM Builds WHERE Arcana = ?', (search_term,))
if search_part == "6":
cursor.execute('SELECT * FROM Builds WHERE Boon1 = ?', (search_term,))
cursor.execute('SELECT * FROM Builds WHERE Boon2 = ?', (search_term,))
cursor.execute('SELECT * FROM Builds WHERE Boon3 = ?', (search_term,))
if search_part == "7":
cursor.execute('SELECT * FROM Builds WHERE Hammer1 = ?', (search_term,))
cursor.execute('SELECT * FROM Builds WHERE Hammer2 = ?', (search_term,))
cursor.execute('SELECT * FROM Builds WHERE Hammer3 = ?', (search_term,))
for Build,Weapon,Aspect,Keepsake1,Keepsake2,Keepsake3,Keepsake4,Arcana,God1,God2,God3,Boon1,Boon2,Boon3,Hammer1,Hammer2,Hammer3 in cursor.fetchall():
clear()
print(f"""
Build name: {Build}
Weapon: {Weapon}
Aspect: {Aspect}
Keepsakes: {Keepsake1} for Erebus, {Keepsake2} for Oceanus, {Keepsake3} for Fields of Mourning and {Keepsake4} for Tartarus
Arcana Cards: {Arcana}
Gods: {God1}, {God2} and {God3}
Boons: {Boon1}, {Boon2} and {Boon3}
Hammers: {Hammer1}, {Hammer2} and {Hammer3}
""")
x = input("To go onto the next build press enter: ")
clear()
elif selection == "4":
build_to_delete = input("Enter build to delete: ")
print()
cursor.execute('DELETE FROM Builds WHERE Build = ?', (build_to_delete,))
bd.commit()
elif selection == "5":
break
else:
print("nIncorrect selection, please try again.n")
t.sleep(1)
bd.close()
if __name__ == '__main__':
main()
I have tried moving the question “What would you like to search for?” separately into each part of the search and the same problem appeared.
0