[Tutor] catching the row that raises IntegrityError in sqlite

Sivaram Neelakantan nsivaram.net at gmail.com
Sun Feb 9 15:19:01 CET 2014


On Sun, Feb 09 2014,Peter Otten wrote:

> Sivaram Neelakantan wrote:
>

[snipped 32 lines]

>
> If nobody here comes up with a good way to find the offending record you 
> could ask in a mailing list/newsgroup dedicated to sqlite (Please report 
> back here if you do). If there is no "official" way you might try the 
> workaround shown below.
>
> 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. 
>

[snipped 62 lines]

Thanks for the code, appreciate the help.

> While this approach seems to work at the moment it will of course break 
> should sqlite decide one day to read records ahead before performing the 
> integrity test. Therefore I recommend the more conservative road to loop 
> over the records explicitly:
>
> for row in records:
>     try:
>        cursor.execute(sql, row)
>     except ...
>         ...

Right, i'll go with this then

[snipped 7 lines]

 sivaram
 -- 



More information about the Tutor mailing list