Digital Technologies Digital Solutions ICT Applied Download Resources Web Applications Games Recycle Bin

SQL Injection - Reset Database

Done. For your information, the following script is used to reset the database. Note that the assigned grades are entirely random:

if os.path.exists("reportcards.db"):
  os.remove("reportcards.db") 
db = sqlite3.connect("reportcards.db")
db.cursor().execute('''
  CREATE TABLE "grades" (
      "ID"	INTEGER NOT NULL UNIQUE,
      "name"	TEXT,
      "code"	TEXT,
      "subject"	TEXT,
      "effort"	TEXT,
      "grade"	TEXT,
      "comment"	TEXT,
      PRIMARY KEY("ID" AUTOINCREMENT)
  );
''')
effort_grades_comments = [("A+","Excellent",""),("A","Excellent",""),("A-","Excellent",""),("B+","Good",""),("B","Good",""),("B-","Good",""),("C+","Satisfactory",""),("C","Satisfactory",""),("C-","Satisfactory",""),("D+","Needs Improvement","Contact me ASAP"),("D","Needs Improvement","Contact me ASAP"),("D-","Needs Improvement","Contact me ASAP"),("E+","Poor","Contact me ASAP"),("E","Poor","Contact me ASAP"),("E-","Poor","Contact me ASAP")]
for student_name in ["Bradley","Angelina","Stephen","Maurice","Lebron","Jimmy","Geoff","Xavier","Michael","Sue","Mary","Larry","Penelope"]:
  for subject in random.sample([ 
    ('10ENG1','English'), ('10MAT1','Maths'), ('10DIG1','Digital Technologies'), ('10HIS1','History'),
    ('10SCI1','Science'), ('10ART1','Art'), ('10MUS1','Music'), ('10HPE1','Health and Physical Education'),
    ('10DRA1','Drama'), ('10GEO1','Geography'), ('10FN1','Food and Nutrition'), ('10DES1','Design'),
  ], 5):
    outcome = random.choice(effort_grades_comments)
    db.cursor().execute("""
      INSERT INTO grades (name, code, subject, effort, grade, comment)
      VALUES (?, ?, ?, ?, ?, ?)
    """, (student_name, subject[0], subject[1], outcome[1], outcome[0], outcome[2]))
db.commit()
db.close()