HACKS FOR THE SQL
import sqlite3
def create_hacks_file():
connection = sqlite3.connect('instance/team.db')
cursor = connection.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS team (
name TEXT,
value TEXT,
league TEXT
)''')
connection.commit()
connection.close()
create_hacks_file()
import sqlite3
def create():
db_file = 'instance/team.db'
name = input("team name ")
value = input("team value ")
league = input(" league of team ")
connection = sqlite3.connect(db_file)
cursor = connection.cursor()
try:
cursor.execute("INSERT INTO team (name, value, league) VALUES (?, ?, ?)", (name, value, league))
connection.commit()
print(f"{name} has been added to the list of teams.")
except sqlite3.Error as error:
print("Error while inserting record", error)
cursor.close()
connection.close()
create()
def read():
try:
connection = sqlite3.connect('instance/team.db')
cursor = connection.cursor()
cursor.execute("SELECT * FROM team")
rows = cursor.fetchall()
if len(rows) > 0:
print("List of teams:")
for row in rows:
print(f"name: {row[0]},\nname: {row[1]},\nvalue: {row[2]},\nleague:")
else:
print("There are no teams in the list.")
except sqlite3.Error as error:
print("Error while connecting to the db_file:", error)
finally:
cursor.close()
connection.close()
read()
def update():
db_file = 'instance/team.db'
connection = sqlite3.connect(db_file)
cursor = connection.cursor()
try:
name = input("Enter the team to update: ")
cursor.execute("SELECT * FROM team WHERE name=?", (name,))
record = cursor.fetchone()
if record:
print("Enter the new information for the team:")
name = input(f"Current name: {record[0]}\nNew name: ")
value = input(f"Current value: {record[1]}\nNew value: ")
league = input(f"Current league: {record[2]}\nNew league: ")
cursor.execute("UPDATE team SET name=?, value=?, league=? WHERE name=?", (name, value, league, name))
connection.commit()
print(f"{name}'s record has been updated.")
else:
print(f"No record found for {name}.")
except sqlite3.Error as error:
print("Error while updating record", error)
cursor.close()
connection.close()
update()
def delete():
connection = sqlite3.connect('instance/team.db')
cursor = connection.cursor()
name = input("Enter the name you want to delete: ")
cursor.execute("SELECT * FROM team WHERE name=?", (name,))
row = cursor.fetchone()
if row:
confirm = input(f"Are you sure you want to delete {name}? (y/n): ")
if confirm.lower() == 'y':
cursor.execute("DELETE FROM team WHERE brand=?", (name,))
connection.commit()
print(f"{name} has been deleted from the list of teams ")
else:
print(f"{name} not found in the list teams.")
cursor.close()
connection.close()
delete()
def table():
operation = input("Enter: (C)reate (R)ead (U)pdate or (D)elete")
if operation.lower() == 'c':
print("Create Operation")
create()
elif operation.lower() == 'r':
print("Read Operation")
read()
elif operation.lower() == 'u':
print("Update Operation")
update()
elif operation.lower() == 'd':
print("Delete Operation")
delete()
elif len(operation)==0:
return
else:
print("Please enter c, r, u, or d")
table()
try:
table()
except:
print("Perform Jupyter 'Run All' prior to starting table")
table()