vendredi 3 avril 2015

Unique Constraint in sqlite does not always raise IntegrityError

I am using Python's sqlite3 wrappers:


I have a table that I create using:



CREATE TABLE IF NOT EXISTS patientsname (id INTEGER PRIMARY KEY AUTOINCREMENT, original, cleaned, study INTEGER, UNIQUE(original, study), FOREIGN KEY(study) REFERENCES studyinstanceuid(id))


If I try to insert multiple time for the same (original, id) I usually get:



IntegrityError: UNIQUE constraint failed: patientsname.original, patientsname.study


every once in a while I get (I have seen on OSX):



OperationalError: UNIQUE constraint failed: patientsname.original, patientsname.study


and seen on Linux:



DatabaseError: UNIQUE constraint failed: patientsname.original, patientsname.study


What is the correct way to catch the unique constraint violation?


Aucun commentaire:

Enregistrer un commentaire