I am coding with python and using SQLite. I need to update a table using the UPDATE and WHERE statements. The challenge is that both values for the WHERE and UPDATE statements must be variables. I have done some research and found this link Sqlite3 Updating Row Defined by a Variable and this https://www.tutorialspoint.com/sqlite/sqlite_update_query.htm
def studentlist():
'''Checks if a student is checked in any class, inserts the status into the
student list table Displays a list of all students and their class status'''
c.execute("SELECT StudentID FROM StudentTable")
all_students = c.fetchall()
c.execute("SELECT StudentID FROM CheckedInTable")
selected_student_id = c.fetchall()
print("The student id in the studentlist is:", selected_student_id,)
for i in all_students:
if i in selected_student_id:
student_attendance = 'Attending a class'
c.execute("UPDATE StudentlistTable set ClassAttend = ?", (student_attendance), "WHERE StudentID = ?", (i))
conn.commit()
else:
student_attendance = "Not in class"
c.execute("UPDATE StudentlistTable set ClassAttend = ?", (student_attendance))
conn.commit()
studentlist()
Upon running the code, I receive the following error
c.execute("UPDATE StudentlistTable set ClassAttend = ?", (student_attendance), "WHERE StudentID = ?", (i))
TypeError: function takes at most 2 arguments (4 given)
Any help would be highly appreciated.