import sqlite3

database = 'instance/sqlite.db'

def schema():
    conn = sqlite3.connect(database)
    cursor = conn.cursor()
    results = cursor.execute("PRAGMA table_info('football')").fetchall()
    for row in results:
        print(row)
    conn.close()
    
schema()
(0, 'id', 'INTEGER', 1, None, 1)
(1, '_name', 'VARCHAR(255)', 1, None, 0)
(2, '_number', 'INTEGER', 1, None, 0)
(3, '_wins', 'INTEGER', 1, None, 0)
(4, '_losses', 'INTEGER', 1, None, 0)
import sqlite3

def read():
    conn = sqlite3.connect(database)
    cursor = conn.cursor()
    results = cursor.execute('SELECT * FROM football').fetchall()
    if len(results) == 0:
        print("Table is empty")
    else:
        for row in results:
            print(row)
    cursor.close()
    conn.close()
    
#read()
import sqlite3

def create():
    name = input("Enter your name:")
    number = input("Enter your number:")
    wins = input("Enter your wins:")
    losses = input("Enter your losses:")
    conn = sqlite3.connect(database)
    cursor = conn.cursor()

    try:
        cursor.execute("INSERT INTO football (_name, _number, _wins, _losses) VALUES (?, ?, ?, ?)", (name, number, wins, losses))
        
        conn.commit()
        print(f"A new player record {name} has been created")
                
    except sqlite3.Error as error:
        print("Error while executing the INSERT:", error)

    cursor.close()
    conn.close()
    
#create()
import sqlite3

def update():
    name = input("Enter name to update")
    number = input("Enter updated number")
    wins = input("Enter updated wins")
    losses = input("Enter updated losses")

    conn = sqlite3.connect(database)

    cursor = conn.cursor()

    try:
        cursor.execute("UPDATE football SET _number = ? WHERE _name = ?", (number, name))
        cursor.execute("UPDATE football SET _wins = ? WHERE _name = ?", (wins, name))
        cursor.execute("UPDATE football SET _losses = ? WHERE _name = ?", (losses, name))
        if cursor.rowcount == 0:
            print(f"No name {name} was not found in the table")
        else:
            print(f"The row with user id {name} the password has been successfully updated")
            conn.commit()
    except sqlite3.Error as error:
        print("Error while executing the UPDATE:", error)
        
    
    cursor.close()
    conn.close()
    
#update()
import sqlite3

def delete():
    name = input("Enter player name to delete")

    conn = sqlite3.connect(database)

    cursor = conn.cursor()
    
    try:
        cursor.execute("DELETE FROM football WHERE _name = ?", (name,))
        if cursor.rowcount == 0:
            print(f"No name {name} was not found in the table")
        else:
            print(f"The row with name {name} was successfully deleted")
        conn.commit()
    except sqlite3.Error as error:
        print("Error while executing the DELETE:", error)
        
    cursor.close()
    conn.close()
    
#delete()
def menu():
    operation = input("Enter: (C)reate (R)ead (U)pdate or (D)elete or (S)chema")
    if operation.lower() == 'c':
        create()
    elif operation.lower() == 'r':
        read()
    elif operation.lower() == 'u':
        update()
    elif operation.lower() == 'd':
        delete()
    elif operation.lower() == 's':
        schema()
    elif len(operation)==0:
        return
    else:
        print("Please enter c, r, u, or d") 
    menu()
        
try:
    menu()
except:
    print("Perform Jupyter 'Run All' prior to starting menu")
A new player record Justin Herbert has been created
(1, 'Patrick Mahomes', 15, 64, 16)
(2, 'JJ Watt', 99, 77, 74)
(3, 'Russell Wilson', 3, 108, 64)
(4, 'Travis Kelce', 87, 105, 39)
(5, 'Joe Burrow', 9, 24, 17)
(6, 'Trevor Lawrence', 16, 12, 22)
(11, 'Patrick Mahomes', 15, 64, 16)
(12, 'JJ Watt', 99, 77, 74)
(13, 'Russell Wilson', 3, 108, 64)
(14, 'Travis Kelce', 87, 105, 39)
(15, 'Joe Burrow', 9, 24, 17)
(16, 'Trevor Lawrence', 16, 12, 22)
(17, 'Kaiden Do', 50, 60, 30)
(18, 'Justin Herbert', 10, 29, 13)
No name Justin Herbet was not found in the table
The row with user id Justin Herbert the password has been successfully updated
(1, 'Patrick Mahomes', 15, 64, 16)
(2, 'JJ Watt', 99, 77, 74)
(3, 'Russell Wilson', 3, 108, 64)
(4, 'Travis Kelce', 87, 105, 39)
(5, 'Joe Burrow', 9, 24, 17)
(6, 'Trevor Lawrence', 16, 12, 22)
(11, 'Patrick Mahomes', 15, 64, 16)
(12, 'JJ Watt', 99, 77, 74)
(13, 'Russell Wilson', 3, 108, 64)
(14, 'Travis Kelce', 87, 105, 39)
(15, 'Joe Burrow', 9, 24, 17)
(16, 'Trevor Lawrence', 16, 12, 22)
(17, 'Kaiden Do', 50, 60, 30)
(18, 'Justin Herbert', 10, 25, 24)
The row with name Justin Herbert was successfully deleted
(1, 'Patrick Mahomes', 15, 64, 16)
(2, 'JJ Watt', 99, 77, 74)
(3, 'Russell Wilson', 3, 108, 64)
(4, 'Travis Kelce', 87, 105, 39)
(5, 'Joe Burrow', 9, 24, 17)
(6, 'Trevor Lawrence', 16, 12, 22)
(11, 'Patrick Mahomes', 15, 64, 16)
(12, 'JJ Watt', 99, 77, 74)
(13, 'Russell Wilson', 3, 108, 64)
(14, 'Travis Kelce', 87, 105, 39)
(15, 'Joe Burrow', 9, 24, 17)
(16, 'Trevor Lawrence', 16, 12, 22)
(17, 'Kaiden Do', 50, 60, 30)
(1, 'Patrick Mahomes', 15, 64, 16)
(2, 'JJ Watt', 99, 77, 74)
(3, 'Russell Wilson', 3, 108, 64)
(4, 'Travis Kelce', 87, 105, 39)
(5, 'Joe Burrow', 9, 24, 17)
(6, 'Trevor Lawrence', 16, 12, 22)
(11, 'Patrick Mahomes', 15, 64, 16)
(12, 'JJ Watt', 99, 77, 74)
(13, 'Russell Wilson', 3, 108, 64)
(14, 'Travis Kelce', 87, 105, 39)
(15, 'Joe Burrow', 9, 24, 17)
(16, 'Trevor Lawrence', 16, 12, 22)
(17, 'Kaiden Do', 50, 60, 30)
read()
(1, 'Patrick Mahomes', 15, 64, 16)
(2, 'JJ Watt', 99, 77, 74)
(3, 'Russell Wilson', 3, 108, 64)
(4, 'Travis Kelce', 87, 105, 39)
(5, 'Joe Burrow', 9, 24, 17)
(6, 'Trevor Lawrence', 16, 12, 22)
(11, 'Patrick Mahomes', 15, 64, 16)
(12, 'JJ Watt', 99, 77, 74)
(13, 'Russell Wilson', 3, 108, 64)
(14, 'Travis Kelce', 87, 105, 39)
(15, 'Joe Burrow', 9, 24, 17)
(16, 'Trevor Lawrence', 16, 12, 22)
(17, 'Kaiden Do', 50, 60, 30)