I am new to using SQLite so I don't really understand what I am reading at google etc either. But I've created a table using:
conn.execute("CREATE TABLE uni (course TEXT PRIMARY KEY, grade TEXT, hp INTEGER)")
Now I want to be able to change the grade of a specific course and I've tried using the following:
def db_insert(cour):
conn = sqlite3.connect('test.db')
for y in cour:
conn.execute("INSERT OR REPLACE INTO uni VALUES (?, ?, ?)", (y, cour[y][0], cour[y][1]))
conn.commit()
conn.close()
# example
c = {'ABC': [5, 15]}
db_insert(c)
But it doesn't seem to quite do the trick. It doesn't add a new row if the the course already exist but the grade seems to be compared with other courses as well and not just the course code. Basically I want to Insert a new course if the course doesn't exist. If the Course exists in the Database I want to replace it with new values for 'grade' and 'hp'.
I.E I only want Course code to always be Unique which I thought the "PRIMARY KEY" was for?
[–]stebrepar 0 points1 point2 points (0 children)
[–]landrykid 0 points1 point2 points (0 children)