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
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
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
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 :
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
I don't know if it's the good way, but we can use preg_replace in pwg_query (only for postgresql).
Something like:
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...
Offline