I have a gradebook that I've used for a couple years. I'm trying to clean it up a little because a colleague wants to use it, but it's not really user ready, just personally ready. Anyway, I was trying to automate updating my student list. I tried the following:
import csv
import sqlite3
f = csv.reader(open('students.csv'))
db = sqlite3.connect('gradebook.db')
cursor = db.cursor()
for row in f:
print row
cursor.execute('INSERT OR REPLACE INTO students (id, name, class, gender, birthday, something, period, section_number, subject, begin_date, end_date, status, absents, tardies) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)', row)
db.commit()
db.close()
This works for new students, BUT, I also have a couple columns in my database that aren't referenced by the CSV dump from school (notes, current chapter, etc). When I run the above code, anything I have in the non-referenced columns gets set to NULL. Is there a way to preserve columns not referenced in the execute command?
EDIT: Tried a bunch of different things, through my incompetence, nothing worked. Ended up with the following in a loop, just got an error:
cursor.execute('INSERT OR REPLACE INTO students (notes, id, name, class, gender,
birthday, something, period, section_number, subject, begin_date, end_date,
status, absents, tardies) VALUES ((select notes from students where id =
row[0]),?,?,?,?,?,?,?,?,?,?,?,?,?,?)', row)
It's the notes that I'm trying to save. All the other fields can be updated, based on the student's ID. I'm giving up for a little while. Getting too frustrated.