From a39d699f90feb359ab994b3d77d71006060afecc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Mar 2012 19:11:39 +0200 Subject: Fix a bug in PDO's insert_id() (PostgreSQL-specific) --- system/database/drivers/pdo/pdo_driver.php | 32 +++++++++--------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'system') diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 44e93a042..dd803aba1 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -509,33 +509,19 @@ class CI_DB_pdo_driver extends CI_DB { /** * Insert ID - * - * @access public - * @return integer + * + * @return int */ - function insert_id($name=NULL) + public function insert_id($name = NULL) { - if ($this->pdodriver == 'pgsql') - { - //Convenience method for postgres insertid - $v = $this->_version(); - - $table = func_num_args() > 0 ? func_get_arg(0) : NULL; - - if ($table == NULL && $v >= '8.1') - { - $sql='SELECT LASTVAL() as ins_id'; - } - - $query = $this->query($sql); - $row = $query->row(); - - return $row->ins_id; - } - else + if ($this->pdodriver === 'pgsql' && $name === NULL && $this->_version() >= '8.1') { - return $this->conn_id->lastInsertId($name); + $query = $this->query('SELECT LASTVAL() AS ins_id'); + $query = $query->row(); + return $query->ins_id; } + + return $this->conn_id->lastInsertId($name); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b