[Tutor] catching the row that raises IntegrityError in sqlite

Sivaram Neelakantan nsivaram.net at gmail.com
Sun Feb 9 14:23:41 CET 2014


On Sun, Feb 09 2014,Steven D'Aprano wrote:

> On Sun, Feb 09, 2014 at 12:03:43PM +0530, Sivaram Neelakantan wrote:
>

[snipped 8 lines]

> When you get an error, and don't know how to interpret it, the first 
> thing to do is to look at the exception and see what it says.
>
> try:
>     # as above
> except sq.IntegrityError as exception:
>     print(exception)
>     dbh.rollback()

I'm sorry I wasn't clear but I do know what kind of error is going to
come; I was trying to make a more helpful exit by printing out the
offending row/row #.   When I tried your suggestion above, I get

'UNIQUE constraint failed: users.id ' which I know but not the
offending row or row number.


 sivaram
 -- 



More information about the Tutor mailing list