Activity 3.1

Source Code

import sqlite3
import os

def main():
    # Connect to the SQLite database
    db = 'activity31.db'
    conn = sqlite3.connect(db)

    done = False
    print("Welcome to the Main Function")
    while not done:
        print("Menu")
        print("E1 - CREATE Example")
        print("E2 - INSERT Example")
        print("E3 - SELECT Example")
        print("E4 - DELETE Example")
        print("Q - Quit")
        choice = input("Choice: ")
        match choice:
            case "E1":
                create(conn)
            case "E2":
                insert(conn)
            case "E3":
                select(conn)
            case "E4":
                delete(conn)
            case "Q":
                print("Quitting!")
                done = True
            # default case
            case _:
                print("Invalid, try again!")

    # close the connection
    conn.close()

def create(conn):
    print("Create Table")

    # Create a cursor object using the cursor() method
    cursor = conn.cursor()

    # Create table query
    sql = ''

    # Execute query
    cursor.execute(sql)
    print("SQL query executed")

def insert(conn):
    print("Insert Data")

    # Create a cursor object using the cursor() method
    cursor = conn.cursor()

    # Insert data into table query
    sql = ""

    # Execute query
    cursor.execute(sql)
    print("SQL query executed")

    # Commit changes
    conn.commit()
    print("changed committed")

def select(conn):
    print("Select Data")

    # Create a cursor object using the cursor() method
    cursor = conn.cursor()

    # SQL Query to SELECT all students
    sql = ""

    # Execute query
    cursor.execute(sql)
    print("SQL query executed")

    # fetch the rows


def delete(conn):
    print("Delete")

    # Create a cursor object using the cursor() method
    cursor = conn.cursor()

    # SQL Query to DELETE all students
    sql = ""

    # Execute query
    cursor.execute(sql)
    print("SQL query executed")

    # Commit Changes
    conn.commit()
    print("changed committed")

main()

Last updated