I have tried getting the registered data from a database the program has created when first run.
database.py
import sqlite3
CREATE_TABLE = """CREATE TABLE IF NOT EXISTS college (
id INTEGER PRIMARY KEY,
FirstName TEXT,
SecondName TEXT,
Position TEXT);"""
INSERT_DATA = "INSERT INTO college (FirstName, SecondName, Position) VALUES (?, ?, ?);"
DISPLAY_DATA = "SELECT * FROM college WHERE Position = ?;"
def connect():
return sqlite3.connect('databas.db')
def create_table(connection):
with connection:
connection.execute(CREATE_TABLE)
def insert_data(connection, FirstName, SecondName, Position):
with connection:
connection.execute(INSERT_DATA, (FirstName, SecondName, Position))
def request_data(connection, position):
with connection:
return connection.execute(DISPLAY_DATA, (position,)).fetchall()
api.py
import database
API_MENU = """
--- Student Database ---
1) Register new student
2) Delete
3) Show students
4) Register new staff
5) Delete
6) Show staff
7) >> Quit the program
Your choice: """
def main():
connection = database.connect()
database.create_table(connection)
while (choice := input(API_MENU)) != "7":
if choice == "1":
FirstName = "Julius"
SecondName = "Jessie"
Position = "Student"
database.insert_data(connection, FirstName, SecondName, Position)
elif choice == "2":
database.request_data(connection, "Student")
elif choice == "3":
pass
elif choice == "4":
pass
elif choice == "5":
pass
elif choice == "6":
pass
else:
print("Invalid input, please try again!")
main()
I am simply not being returned any data after I have registered the data using option 1. When running the code and choosing option 1, you should input a name, surname and position (Student / Staff) and then write that to the database (i have just defined strings for the purpose of putting the code here) and then choosing the option 2 should return the data that has "Student" as a position however it does not return any data.