Skip to content

Commit

Permalink
Feature 1255 : bug in pwg_session_write() with postgresql.
Browse files Browse the repository at this point in the history
replace into doesn't exists. Must do two queries

git-svn-id: http://piwigo.org/svn/trunk@4886 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
nikrou committed Feb 13, 2010
1 parent ddf5199 commit 78b517b
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion include/dblayer/functions_pgsql.inc.php
Expand Up @@ -70,8 +70,36 @@ function pwg_query($query)
{
global $conf,$page,$debug,$t2;

$replace_pattern = '`REPLACE INTO\s(\S*)\s*([^)]*\))\s*VALUES\(([^,]*),(.*)\)\s*`mi';

$start = get_moment();
($result = pg_query($query)) or die($query."\n<br>".pg_last_error());

if (preg_match($replace_pattern, $query, $matches)
&& $matches[1]==SESSIONS_TABLE)
{
$select_query = '
SELECT id FROM '.$matches[1].'
WHERE id='.$matches[3];
( $result = pg_query($select_query)) or die($query."\n<br>".pg_last_error());
if (pwg_db_num_rows($result)==1)
{
$query = '
UPDATE '.$matches[1].'
SET expiration=now()
WHERE id='.$matches[3];
}
else
{
$query = '
INSERT INTO '.$matches[1].'
'.$matches[2].' VALUES('.$matches[3].','.$matches[4].')';
}
( $result = pg_query($query)) or die($query."\n<br>".pg_last_error());
}
else
{
($result = pg_query($query)) or die($query."\n<br>".pg_last_error());
}

$time = get_moment() - $start;

Expand Down

0 comments on commit 78b517b

Please sign in to comment.