Fwd: Re: [imp] horde prefs and pgsql errors

Jan Schneider jan@horde.org
Tue, 14 May 2002 14:51:01 +0200



----- Weitergeleitete Nachricht von Stephen Grier <s.e.grier@qmul.ac.uk> ---
--
    Datum: Tue, 14 May 2002 13:46:19 +0100
    Von: Stephen Grier <s.e.grier@qmul.ac.uk>
Antwort an: Stephen Grier <s.e.grier@qmul.ac.uk>
 Betreff: Re: [imp] horde prefs and pgsql errors
      An: Jan Schneider <jan@horde.org>

I think 'REPLACE INTO' is specific to mySQL, and its certainly not standard 
sql.
Probably not a good idea to use it in the horde/imp code. Apparently, this
function is available in mySQL because it doesn't handle transactions 
properly.

One could use the pg_affected_rows() and/or mysql_affected_rows() functions 
to
check if an update caused a change, something like this:

$result = $this->db->query("update horde_prefs ...");
if (!pg_affected_rows($result)){
    $this->db->query("insert into horde_prefs ...");
    ....

and do an insert if the update failed to change anything (indicating the 
value has
not been previously set).

Apart from this, doing a select appears to be the only sensible way to check
whether a row exists in the table.

Jan Schneider wrote:
> 
> Zitat von Stephen Grier <s.e.grier@qmul.ac.uk>:
> 
> > 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.
> 
> What about using REPLACE INTO? Is that portable across DBMS'?
> 
> Jan.
> 
> --
> http://www.horde.org - The Horde Project
> http://www.ammma.de - discover your knowledge
> http://www.tip4all.de - Deine private Tippgemeinschaft

-- 

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


----- Ende der weitergeleiteten Nachricht -----


Jan.

--
http://www.horde.org - The Horde Project
http://www.ammma.de - discover your knowledge
http://www.tip4all.de - Deine private Tippgemeinschaft