Skip to content

Commit 78b517b

Browse files
author
nikrou
committed
Feature 1255 : bug in pwg_session_write() with postgresql.
replace into doesn't exists. Must do two queries git-svn-id: http://piwigo.org/svn/trunk@4886 68402e56-0260-453c-a942-63ccdbb3a9ee
1 parent ddf5199 commit 78b517b

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

include/dblayer/functions_pgsql.inc.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,36 @@ function pwg_query($query)
7070
{
7171
global $conf,$page,$debug,$t2;
7272

73+
$replace_pattern = '`REPLACE INTO\s(\S*)\s*([^)]*\))\s*VALUES\(([^,]*),(.*)\)\s*`mi';
74+
7375
$start = get_moment();
74-
($result = pg_query($query)) or die($query."\n<br>".pg_last_error());
76+
77+
if (preg_match($replace_pattern, $query, $matches)
78+
&& $matches[1]==SESSIONS_TABLE)
79+
{
80+
$select_query = '
81+
SELECT id FROM '.$matches[1].'
82+
WHERE id='.$matches[3];
83+
( $result = pg_query($select_query)) or die($query."\n<br>".pg_last_error());
84+
if (pwg_db_num_rows($result)==1)
85+
{
86+
$query = '
87+
UPDATE '.$matches[1].'
88+
SET expiration=now()
89+
WHERE id='.$matches[3];
90+
}
91+
else
92+
{
93+
$query = '
94+
INSERT INTO '.$matches[1].'
95+
'.$matches[2].' VALUES('.$matches[3].','.$matches[4].')';
96+
}
97+
( $result = pg_query($query)) or die($query."\n<br>".pg_last_error());
98+
}
99+
else
100+
{
101+
($result = pg_query($query)) or die($query."\n<br>".pg_last_error());
102+
}
75103

76104
$time = get_moment() - $start;
77105

0 commit comments

Comments
 (0)