I'm doing a Software Engineering Project for one of my final courses as a Comp Sci major and I'm getting hungup on this particular error while I'm trying to do my data/unit testing of the methods before merging my methods with our teammates GUI. Anyone who can help me solve this issue is my hero
class Student:
def __init__(self, StudentID, StudentName, conn: sql.Connection, curs: sql.Cursor):
self.StudentID = StudentID
self.StudentName = StudentName
def addStudent(self, curs: sql.Cursor):
query = f"""INSERT INTO Student
(StudentID, StudentName)
VALUES ({self.StudentID},{self.StudentName})"""
curs.execute(query)
As commented, consider parameterization. Right now your string formatting does not enclose potential string values in single quotes in
VALUESclause. With parameterization which involves placeholders in a prepared SQL statement and binding values in the execution call, you do not need to worry about such quotes.Above assumes you are using the
sqlite3DB-API which uses qmark placeholder,?. Most other Python DB-APIs use%sfor placeholders (not to be confused with the outmoded string modulo format symbol).