[Tutor] catching the row that raises IntegrityError in sqlite

eryksun eryksun at gmail.com
Mon Feb 10 00:22:03 CET 2014


On Sun, Feb 9, 2014 at 5:20 AM, Peter Otten <__peter__ at web.de> wrote:
>
> The idea here is to wrap the iterable of records to be inserted in the Iter
> class which keeps track of the last accessed row.

You could also use a parameters iterator, e.g. `it = iter(to_db)`.
Then for an IntegrityError, list the remaining records and use that to
infer the last record. This way uses an efficient built-in list
iterator instead of a generator.

http://docs.python.org/3/library/sqlite3#sqlite3.Cursor.executemany

I can't see why the implementation would change in future versions.
Internally it gets an iterator and executes the statement for each
record in a loop. I don't see any point to reading ahead.


More information about the Tutor mailing list