From 569e93cd6ba7a50bab07d6b26aa8b61c8a24a34a Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 8 Mar 2012 02:55:04 +0000 Subject: [PATCH] postgres requires a sequence name to be passed to get_last_insert_id --- contrib/pools/main.php | 2 +- core/database.class.php | 9 +++++++-- ext/comment/main.php | 2 +- ext/image/main.php | 8 +------- ext/user/main.php | 2 +- install.php | 2 +- 6 files changed, 12 insertions(+), 13 deletions(-) mode change 100755 => 100644 install.php diff --git a/contrib/pools/main.php b/contrib/pools/main.php index 8ca72765..585fd3ad 100644 --- a/contrib/pools/main.php +++ b/contrib/pools/main.php @@ -340,7 +340,7 @@ class Pools extends Extension { VALUES (:uid, :public, :title, :desc, now())", array("uid"=>$user->id, "public"=>$public, "title"=>$_POST["title"], "desc"=>$_POST["description"])); - $result['poolID'] = $database->get_last_insert_id(); + $result['poolID'] = $database->get_last_insert_id('pools_id_seq'); log_info("pools", "Pool {$result["poolID"]} created by {$user->name}"); diff --git a/core/database.class.php b/core/database.class.php index 7ff1617b..2f63ab1a 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -403,8 +403,13 @@ class Database { /** * get the ID of the last inserted row */ - public function get_last_insert_id() { - return $this->db->lastInsertId(); + public function get_last_insert_id($seq) { + if($this->engine->name == "pgsql") { + return $this->db->lastInsertId($seq); + } + else { + return $this->db->lastInsertId(); + } } diff --git a/ext/comment/main.php b/ext/comment/main.php index 0cc84ce3..2b691c34 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -500,7 +500,7 @@ class CommentList extends Extension { "INSERT INTO comments(image_id, owner_id, owner_ip, posted, comment) ". "VALUES(:image_id, :user_id, :remote_addr, now(), :comment)", array("image_id"=>$image_id, "user_id"=>$user->id, "remote_addr"=>$_SERVER['REMOTE_ADDR'], "comment"=>$comment)); - $cid = $database->get_last_insert_id(); + $cid = $database->get_last_insert_id('comments_id_seq'); $snippet = substr($comment, 0, 100); $snippet = str_replace("\n", " ", $snippet); $snippet = str_replace("\r", " ", $snippet); diff --git a/ext/image/main.php b/ext/image/main.php index 4b306ab6..c999a5bc 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -328,13 +328,7 @@ class ImageIO extends Extension { "hash"=>$image->hash, "ext"=>$image->ext, "width"=>$image->width, "height"=>$image->height, "source"=>$image->source ) ); - //$database->Execute("UPDATE users SET image_count = image_count+1 WHERE id = :id ", array("id"=>$user->id)); - if($database->engine->name == "pgsql") { - $image->id = $database->get_one("SELECT id FROM images WHERE hash=:hash", array("hash"=>$image->hash)); - } - else { - $image->id = $database->get_last_insert_id(); - } + $image->id = $database->get_last_insert_id('images_id_seq'); log_info("image", "Uploaded Image #{$image->id} ({$image->hash})"); diff --git a/ext/user/main.php b/ext/user/main.php index 0d5652f0..27e59e01 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -339,7 +339,7 @@ class UserPage extends Extension { $database->Execute( "INSERT INTO users (name, pass, joindate, email, class) VALUES (:username, :hash, now(), :email, :class)", array("username"=>$event->username, "hash"=>$hash, "email"=>$email, "class"=>$class)); - $uid = $database->get_last_insert_id(); + $uid = $database->get_last_insert_id('users_id_seq'); log_info("user", "Created User #$uid ({$event->username})"); } diff --git a/install.php b/install.php old mode 100755 new mode 100644 index 32fd376e..3ef97def --- a/install.php +++ b/install.php @@ -354,7 +354,7 @@ function insert_defaults() { // {{{ $db = new Database(); $db->execute("INSERT INTO users(name, pass, joindate, class) VALUES(:name, :pass, now(), :class)", Array("name" => 'Anonymous', "pass" => null, "class" => 'anonymous')); - $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", Array("name" => 'anon_id', "value" => $db->get_last_insert_id())); + $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", Array("name" => 'anon_id', "value" => $db->get_last_insert_id('users_id_seq'))); if(check_im_version() > 0) { $db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", Array("name" => 'thumb_engine', "value" => 'convert'));