I wish to execute the following statement:
c.execute('INSERT INTO artists (name, score) VALUES("Buddy Rich", 10), ("Candido", 9), ("Charlie Byrd", 8);')
but instead of hardcoding the values as above, I have them in a variable:
scores = (("Buddy Rich", 10), ("Candido", 9), ("Charlie Byrd", 8))
how do I use scores
with execute()
, where scores
could contain any number of values?
UPDATE
I wish to be able to guarantee that if the data is inserted into the table, that all the data, or none of the data, is inserted even if there is a program crash. If there is a program crash while running executemany
, is there a risk that only some of the rows get added?
For example, can this result in only some of the rows being added:
try:
c.executemany('INSERT INTO artists (name, score) VALUES (?, ?)', scores)
except:
c.commit()