diff options
author | nikrou <nikrou@piwigo.org> | 2010-02-13 21:27:42 +0000 |
---|---|---|
committer | nikrou <nikrou@piwigo.org> | 2010-02-13 21:27:42 +0000 |
commit | 78b517bde6abed39b858f0854c3fca5d82bed4b9 (patch) | |
tree | 3969a66037d5d5c833f446e5dd51bea174a80c35 /include/dblayer/functions_pgsql.inc.php | |
parent | ddf51992f0787e92d9f6fa1dba2bbb31e50a685d (diff) |
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
Diffstat (limited to '')
-rw-r--r-- | include/dblayer/functions_pgsql.inc.php | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/include/dblayer/functions_pgsql.inc.php b/include/dblayer/functions_pgsql.inc.php index a04da9620..6dcf26f6d 100644 --- a/include/dblayer/functions_pgsql.inc.php +++ b/include/dblayer/functions_pgsql.inc.php @@ -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; |