aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authornikrou <nikrou@piwigo.org>2010-02-15 19:49:04 +0000
committernikrou <nikrou@piwigo.org>2010-02-15 19:49:04 +0000
commitc1d6177df9ebb853217958d91aba26f35f66a497 (patch)
treebff2b1998cc4d8030a48a96c39104887066e53dd /include
parent78b517bde6abed39b858f0854c3fca5d82bed4b9 (diff)
Feature 1255 :
update pwg_db_insert_id() function. PosgreSQL needs table name to retrieve last insert auto increment id. git-svn-id: http://piwigo.org/svn/trunk@4892 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/dblayer/functions_mysql.inc.php2
-rw-r--r--include/dblayer/functions_pgsql.inc.php10
-rw-r--r--include/dblayer/functions_sqlite.inc.php2
-rw-r--r--include/functions_comment.inc.php2
-rw-r--r--include/ws_functions.inc.php2
5 files changed, 12 insertions, 6 deletions
diff --git a/include/dblayer/functions_mysql.inc.php b/include/dblayer/functions_mysql.inc.php
index 6a29a0e40..f94984514 100644
--- a/include/dblayer/functions_mysql.inc.php
+++ b/include/dblayer/functions_mysql.inc.php
@@ -157,7 +157,7 @@ function pwg_db_real_escape_string($s)
return mysql_real_escape_string($s);
}
-function pwg_db_insert_id()
+function pwg_db_insert_id($table=null, $column='id')
{
return mysql_insert_id();
}
diff --git a/include/dblayer/functions_pgsql.inc.php b/include/dblayer/functions_pgsql.inc.php
index 6dcf26f6d..5337b4aa5 100644
--- a/include/dblayer/functions_pgsql.inc.php
+++ b/include/dblayer/functions_pgsql.inc.php
@@ -192,9 +192,15 @@ function pwg_db_real_escape_string($s)
return pg_escape_string($s);
}
-function pwg_db_insert_id()
+function pwg_db_insert_id($table=null, $column='id')
{
- // select currval('piwigo_user_id_seq');
+ $sequence = sprintf('%s_%s_seq', strtolower($table), $column);
+ $query = '
+SELECT CURRVAL(\''.$sequence.'\');';
+
+ list($id) = pwg_db_fetch_row(pwg_query($query));
+
+ return $id;
}
/**
diff --git a/include/dblayer/functions_sqlite.inc.php b/include/dblayer/functions_sqlite.inc.php
index 1e25305e9..44b33685c 100644
--- a/include/dblayer/functions_sqlite.inc.php
+++ b/include/dblayer/functions_sqlite.inc.php
@@ -214,7 +214,7 @@ function pwg_db_real_escape_string($s)
return $pwg_db_link->escapeString($s);
}
-function pwg_db_insert_id()
+function pwg_db_insert_id($table=null, $column='id')
{
global $pwg_db_link;
diff --git a/include/functions_comment.inc.php b/include/functions_comment.inc.php
index f22aa3f6e..c4f021edf 100644
--- a/include/functions_comment.inc.php
+++ b/include/functions_comment.inc.php
@@ -168,7 +168,7 @@ INSERT INTO '.COMMENTS_TABLE.'
pwg_query($query);
- $comm['id'] = pwg_db_insert_id();
+ $comm['id'] = pwg_db_insert_id(COMMENTS_TABLE);
if (($comment_action=='validate' and $conf['email_admin_on_comment']) or
($comment_action!='validate' and $conf['email_admin_on_comment_validation']))
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 4a9208905..b3b90a027 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -1247,7 +1247,7 @@ SELECT
array($insert)
);
- $image_id = pwg_db_insert_id();
+ $image_id = pwg_db_insert_id(IMAGES_TABLE);
// let's add links between the image and the categories
if (isset($params['categories']))