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()
(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)
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")
read()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/home/kcabralomana/Fastpages/_notebooks/2023-03-19-footballplayersmenu.ipynb Cell 8 in <cell line: 1>()
----> <a href='vscode-notebook-cell://wsl%2Bubuntu/home/kcabralomana/Fastpages/_notebooks/2023-03-19-footballplayersmenu.ipynb#X10sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a> read()

NameError: name 'read' is not defined