the data in my csv file is like this:
081299289X,China Dolls,Lisa See,2014
0345498127,Starter for Ten,David Nicholls,2003
0061053716,Imajica,Clive Barker,1991
05
From the looks of it your CSV contains a header as the first row. Skip it with for example
next(reader, None)
before your for-loop.
As answered on a similar question. I cannot see the header from Ilja Everilä's answer, but of course if there are headers, Everilä is completely right, you need to skip it (or perhaps make it into a map).
My answer propose a general design improvement, since ISBN should probably not be a number that said if there is a header, be aware that this change will hide that error until you inspect the data.
Change database schema (probably preferred)
Change the ISBN type to varchar(255)
Reasoning for preference: Is ISBN actually an integer? I.e. would you ever perform integer operations on it as addition? Or is is an ID that just happens to currently be formatted as numbers? Also ISBN is an ID format outside your control. Do you really want you application to be tightly coupled to the current formatting? What will happen if ISBN changes to include letters in the future?
Alternative, convert the string
Alternatively you can just convert isbn
:
isbnAsNumber = int(isbn.strip().replace("-", ""))
db.execute("INSERT INTO books (isbn, title, author, year) VALUES (:isbn, :title, :author, :year)",
{"isbn": isbnAsNumber, "title": title, "author": author, "year": year})
But I would consider this a dirty solution compared to changing the logical type, as suggested in the first solution.