•  » Engine
  •  » REPLACE INTO syntax and new dblayer

#1 2010-03-15 00:34:11

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
14100

REPLACE INTO syntax and new dblayer

Hi nicolas,

I would like to use the REPLACE INTO syntax on trunk (prior to 2.1). I've read in include/dblayer/functions_pgsql.inc.php that you made a specific code for REPLACE INTO sessions.

Does that mean REPLACE INTO only works with REPLACE INTO sessions? or did you need this specific code for sessions but I can write REPLACE INTO config without worrying for PostgreSQL?

Offline

 

#2 2010-03-15 11:58:08

nicolas
Former Piwigo Team
2004-12-30
1235

Re: REPLACE INTO syntax and new dblayer

plg wrote:

Hi nicolas,

I would like to use the REPLACE INTO syntax on trunk (prior to 2.1). I've read in include/dblayer/functions_pgsql.inc.php that you made a specific code for REPLACE INTO sessions.

Does that mean REPLACE INTO only works with REPLACE INTO sessions? or did you need this specific code for sessions but I can write REPLACE INTO config without worrying for PostgreSQL?

My code was too specific and only work for sessions. REPLACE INTO syntax doesn't exists with posgresql. What do you want to do ?

Offline

 

#3 2010-03-15 12:24:37

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
14100

Re: REPLACE INTO syntax and new dblayer

nicolas wrote:

My code was too specific and only work for sessions. REPLACE INTO syntax doesn't exists with posgresql. What do you want to do ?

I want to do exactly what REPLACE INTO does :-) ie if the row already exists, deletes it first, then insert. But a delete + insert works perfectly, no problem for me, I was just wondering while coding.

Offline

 

#4 2010-03-15 15:13:23

nicolas
Former Piwigo Team
2004-12-30
1235

Re: REPLACE INTO syntax and new dblayer

plg wrote:

nicolas wrote:

My code was too specific and only work for sessions. REPLACE INTO syntax doesn't exists with posgresql. What do you want to do ?

I want to do exactly what REPLACE INTO does :-) ie if the row already exists, deletes it first, then insert. But a delete + insert works perfectly, no problem for me, I was just wondering while coding.

Ok. I think it's what's you want to say but  REPLACE INTO do an update or an insert depending on the line existance!

What do you think about a new function pwg_db_replace_into() (or something like that) that do a replace into for engine that can do it and do two queries (select and update/insert) for others.

It can be something like that for mysql :

Code:

function pwg_db_replace_into($table, $sub_query)
{
   $query = '
REPLACE INTO '.$table.
$sub_query;

   $result = pwg_query($query);
}

code for postgresql will do two queries !

Offline

 

#5 2010-03-15 18:14:13

P@t
Piwigo Team
Nice
2007-06-13
4098

Re: REPLACE INTO syntax and new dblayer

I don't know if it's the good way, but we can use preg_replace in pwg_query (only for postgresql).

Something like:

Code:

function pwg_query($query)
{
  $pattern = '/\s*INSERT\s*INTO\s*(.*)/s';
  $replacement = 'DELETE FROM $1; INSERT INTO $1;';

  $query = preg_replace($pattern, $replacement, $query);

  ...
}

EDIT: forget that, it can't work...


P@t

Offline

 
  •  » Engine
  •  » REPLACE INTO syntax and new dblayer

Board footer

Powered by FluxBB