[imp] horde prefs and pgsql errors

Stephen Grier s.e.grier@qmul.ac.uk
Tue, 14 May 2002 11:32:41 +0100


We are currently running horde-2.0 and imp-3.0, with postgresql-7.1.2 storing user
preferences and turba address books. I recently noticed a large number of the
following messages in the pgsql and info system logs:

postgres[557]: [ID 553393 local0.warning] [544] ERROR:  Cannot insert a duplicate
key into unique index horde_prefs_pkey

One such error message occurs every time a user logs into imp. Most often, horde
seems to be trying to set the last_login preference value.

I traced the cause of these messages to the store() function in
horde-2.0/lib/Prefs/sql.php. I was supprised to see that when setting a pref value
the code tries to do an sql insert, and then an update if the insert fails. This
means that every time a user (with an existing last_login value) logs into imp, an
error message is produced when the insert statement breaks the primary key
constraint on the horde_prefs table.

Would it not be more reasonable for horde to do a select statement on the
horde_prefs table first to see if the value already exists, followed by an update
if it does, or an insert if not? Is there a reason why this would not work? I'll
be making this change to our code if not.

Thanks.

-- 

Stephen Grier				s.e.grier@qmul.ac.uk
Systems Developer			(020) 7882 7642
Computing Services
Queen Mary, University of London