Re: Primary Key Violation Checking

Adrian Klaver <[email protected]>
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
On Monday 29 October 2007 7:02 am, Rich Shepard wrote:
> On Mon, 29 Oct 2007, Adrian Klaver wrote:
> > No that is not necessary. I was just trying to figure out what was
> > happening.
>
>    Me, too, Adrian.
>
> > As to your original question, I think you are going to have to write your
> > own wrap code for the statements. You already have the data you are
> > trying to INSERT/UPDATE. In the case of an IntegrityError you would need
> > to run a query to collect the info from the database for the affected
> > record.
>
>    OK. I won't be re-inventing the wheel, then.
>
> Thanks,
>
> Rich
Now that the caffeine has kicked in on this end I had a change of mind. You 
might want to use INSERT OR REPLACE all the time. It would eliminate the 
error condition by removing preexisting rows that share the UNIQUE 
constraint.

See:
http://sqlite.org/lang_conflict.html

The problem being you might not want those rows deleted automatically. Also 
rows removed in this manner do not call any delete triggers that may be 
present.

-- 
Adrian Klaver
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.