public function insertid()
	{
		$this->connect();
		$insertQuery = $this->getQuery(false, true);
		$table = $insertQuery->__get('insert')->getElements();

		/* find sequence column name */
		$colNameQuery = $this->getQuery(true);
		$colNameQuery->select('column_default')
			->from('information_schema.columns')
			->where(
				"table_name=" . $this->quote(
					$this->replacePrefix(str_replace('"', '', $table[0]))
				), 'AND'
			)
			->where("column_default LIKE '%nextval%'");

		$this->setQuery($colNameQuery);
		$colName = $this->loadRow();
		$changedColName = str_replace('nextval', 'currval', $colName);

		$insertidQuery = $this->getQuery(true);
		$insertidQuery->select($changedColName);
		$this->setQuery($insertidQuery);
		$insertVal = $this->loadRow();

		return $insertVal[0];
	}
public function insertid()
	{
		$this->connect();
		$insertQuery = $this->getQuery(false, true);
		$table = $insertQuery->__get('insert')->getElements();

		/* find sequence column name */
		$colNameQuery = $this->getQuery(true);
		$colNameQuery->select('column_default')
			->from('information_schema.columns')
			->where(
				"table_name=" . $this->quote(
					$this->replacePrefix(str_replace('"', '', $table[0]))
				), 'AND'
			)
			->where("column_default LIKE '%nextval%'");

		$this->setQuery($colNameQuery);
		$colName = $this->loadRow();
		$changedColName = str_replace('nextval', 'currval', $colName);

		$insertidQuery = $this->getQuery(true);
		$insertidQuery->select($changedColName);
		$this->setQuery($insertidQuery);
		$insertVal = $this->loadRow();

		return $insertVal[0];
	}
public function insertid ( ) { $ this -> connect ( ) ; $ insertQuery = $ this -> getQuery ( false , true ) ; $ table = $ insertQuery -> __get ( 'insert' ) -> getElements ( ) ; /* find sequence column name */ $ colNameQuery = $ this -> getQuery ( true ) ; $ colNameQuery -> select ( 'column_default' ) -> from ( 'information_schema.columns' ) -> where ( "table_name=" . $ this -> quote ( $ this -> replacePrefix ( str_replace ( '"' , '' , $ table [ 0 ] ) ) ) , 'AND' ) -> where ( "column_default LIKE '%nextval%'" ) ; $ this -> setQuery ( $ colNameQuery ) ; $ colName = $ this -> loadRow ( ) ; $ changedColName = str_replace ( 'nextval' , 'currval' , $ colName ) ; $ insertidQuery = $ this -> getQuery ( true ) ; $ insertidQuery -> select ( $ changedColName ) ; $ this -> setQuery ( $ insertidQuery ) ; $ insertVal = $ this -> loadRow ( ) ; return $ insertVal [ 0 ] ; }
Method to get the auto-incremented value from the last INSERT statement.
To be called after the INSERT statement, it's MANDATORY to have a sequence on
every primary key table.

To get the auto incremented value it's possible to call this function after
INSERT INTO query, or use INSERT INTO with RETURNING clause.

@example with insertid() call:
$query = $this->getQuery(true);
$query->insert('jos_dbtest')
->columns('title,start_date,description')
->values("'testTitle2nd','1971-01-01','testDescription2nd'");
$this->setQuery($query);
$this->execute();
$id = $this->insertid();

@example with RETURNING clause:
$query = $this->getQuery(true);
$query->insert('jos_dbtest')
->columns('title,start_date,description')
->values("'testTitle2nd','1971-01-01','testDescription2nd'")
->returning('id');
$this->setQuery($query);
$id = $this->loadResult();

@return  integer  The value of the auto-increment field from the last inserted row.

@since   1.0
Method to get the auto - incremented value from the last INSERT statement . To be called after the INSERT statement it s MANDATORY to have a sequence on every primary key table .