[imp] horde prefs and pgsql errors

Jon Parise jon@horde.org
Tue, 14 May 2002 14:34:15 -0400


On Tue, May 14, 2002 at 05:52:01PM +0100, Stephen Grier wrote:

> I have now managed to stop horde/imp from generating these pgsql 'duplicate key'
> errors. I've included the changes to horde-2.0/lib/Prefs/sql.php below (in the
> form of a unified diff). These changes will force sql.php to check for the
> existence of a particular preference value using a select statement. It will then
> perform an sql insert if a value does not already exist, or an update statement if
> one does.

I just committed a slightly modified version of your path to HEAD CVS.
I'll probably merge it into the release branch, as well.

I've actually used a number of different approaches to determining the
existing of a row in order to decided on an update or an insertion,
and your method is probably the cleanest and most portable.

The motivation behind the "test an insert" method was to cut down on
the number of transactions between PHP and the database.  Your method
always requires two queries (a select and an insert or update).  The
old method could sometimes get away with just one query in the case of
a successful insert.
 
-- 
Jon Parise (jon@csh.rit.edu)  .  Information Technology (2001)
http://www.csh.rit.edu/~jon/  :  Computer Science House Member