import sqlite3

def create_connection():
    conn = sqlite3.connect('model.db')
    return conn

def create_table(conn):
    cursor = conn.cursor()
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS students (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            name TEXT NOT NULL,
            gpa REAL NOT NULL,
            student_id INTEGER NOT NULL,
            ap_score INTEGER NOT NULL
        )
    ''')
    conn.commit()

def create_student(conn, name, gpa, student_id, ap_score):
    cursor = conn.cursor()
    cursor.execute('INSERT INTO students (name, gpa, student_id, ap_score) VALUES (?, ?, ?, ?)', (name, gpa, student_id, ap_score))
    conn.commit()

def read_students(conn):
    cursor = conn.cursor()
    cursor.execute('SELECT * FROM students')
    return cursor.fetchall()

def update_student(conn, id, name, gpa, student_id, ap_score):
    cursor = conn.cursor()
    cursor.execute('UPDATE students SET name = ?, gpa = ?, student_id = ?, ap_score = ? WHERE id = ?', (name, gpa, student_id, ap_score, id))
    conn.commit()

def delete_student(conn, id):
    cursor = conn.cursor()
    cursor.execute('DELETE FROM students WHERE id = ?', (id,))
    conn.commit()

# Examples:
conn = create_connection()
create_table(conn)
create_student(conn, 'Fred', 3.8, 12345, 4)
create_student(conn, 'Bob', 3.5, 67890, 5)
create_student(conn,'Joesph', 4.0, 13579, 5)
print(read_students(conn))
update_student(conn, 1,'Joe', 3.9 ,12345 ,4)
delete_student(conn ,2)
print(read_students(conn))
conn.close()
[(1, 'Joe', 3.9, 12345, 4), (3, 'Charlie', 4.0, 13579, 5), (4, 'Fred', 3.8, 12345, 4), (5, 'Bob', 3.5, 67890, 5), (6, 'Joesph', 4.0, 13579, 5), (7, 'Fred', 3.8, 12345, 4), (8, 'Bob', 3.5, 67890, 5), (9, 'Joesph', 4.0, 13579, 5)]
[(1, 'Joe', 3.9, 12345, 4), (3, 'Charlie', 4.0, 13579, 5), (4, 'Fred', 3.8, 12345, 4), (5, 'Bob', 3.5, 67890, 5), (6, 'Joesph', 4.0, 13579, 5), (7, 'Fred', 3.8, 12345, 4), (8, 'Bob', 3.5, 67890, 5), (9, 'Joesph', 4.0, 13579, 5)]

Extra: Quiz on Defining classes and creating objects and Property decorators

- What is a class?
- How do you create an object from a class?
- What is a property decorator?
- What is a class method?
- What is a static method?