Return the last inserted id
If the sequence name is not sent, throws an exception

@param string $sequence name

@return mixed last id
@throws \PDOException
558766
public function lastInsertId($sequence=null)
    {
        if (!$sequence) {
            throw new \PDOException("SQLSTATE[IM001]: Driver does not support this function: driver does not support getting attributes in system_requirements");
        }
        $id = 0;
        try {
            $stmt = $this->query("select $sequence.currval from dual");
            $data = $stmt->fetch(\PDO::FETCH_ASSOC);
            $id   = intval($data["CURRVAL"]);
        } catch (\PDOException $e) {
            $id   = -1;
        }
        return $id;
    }
139176
public function insertGetId(array $values, $sequence = null)
    {
        $result = $this->collection->insertOne($values);

        if (1 == (int) $result->isAcknowledged()) {
            if (is_null($sequence)) {
                $sequence = '_id';
            }

            // Return id
            return $sequence == '_id' ? trim($result->getInsertedId()) : $values[$sequence];
        }

        return null;
    }
1188828
public function nextSequence($sequence)
    {
        $start = $this->_current;
        $result = '';
        $len = strlen($sequence);
        $lastToken = substr($sequence, -1);

        while (($content = $this->next($lastToken)) !== null) {
            $result .= $content;
            if (strlen($result) >= $len && substr_compare($result, $sequence, -$len, $len) === 0) {
                return $result;
            }
        }
        $this->_current = $start;
    }
572272
public function lastSequenceId($sequenceName)
    {
        $this->_connect();
        $sequenceName = str_replace($this->getQuoteIdentifierSymbol(), '', (string) $sequenceName);
        $value = $this->fetchOne("SELECT CURRVAL("
               . $this->quote($this->quoteIdentifier($sequenceName, true))
               . ")");
        return $value;
    }
1168154
public function lastInsertId($table = null, $column = null)
    {
        $row = null;
        if ($column && $this->columnCount()) {
            $row = $this->fetch(static::FETCH_TYPE_ASSOC);
        }
        if (isset($row[$column])) {
            return $row[$column];
        }

        return $this->_driver->lastInsertId($table, $column);
    }
180824
public function insertGetId(array $values, $sequence = null)
    {
        $sql = $this->grammar->compileInsertGetId($this, $values, $sequence);
        $values = $this->cleanBindings($values);
        $this->connection->query($sql, $values);

        return $this->connection->insert_id();
    }
882996
public function lastInsertId($table = null, $column = null)
    {
        $this->connect();

        return $this->_connection->lastInsertId($table);
    }
347291
public function getTransaction( $transaction = self::TRANSACTION_LAST_USED, $throwExceptionIfNotFound = true )
    {

        if( $transaction === self::TRANSACTIONS_ALL ) {
            return array_keys( $this->queue );
        }

        if( $transaction === self::TRANSACTION_LAST_CREATED ) {
            if( !$this->queue) {
                $this->newTransaction();
            }
            $queue = array_keys( $this->queue );
            return array_pop( $queue );
        }

        if( $transaction === self::TRANSACTION_LAST_USED ) {
            if( !$this->queue) {
                $this->newTransaction();
            }
            return $this->lastTransaction;
        }

        if( $transaction === self::TRANSACTION_NEW ) {
            return $this->newTransaction();
        }

        if( !array_key_exists( $transaction, $this->queue ) ) {
            if( $throwExceptionIfNotFound ) {
                throw new TransactionDoesNotExistException(
                    "Transaction with this name `{$transaction}` doesn't exist. Sorry."
                );
            }
            return null;
        }

        return $transaction;

    }
301147
public function nextSequenceId($sequenceName)
    {
        $sql = 'SELECT '.$this->_adapter->quoteIdentifier($sequenceName).'.NEXTVAL FROM '
               .'systables WHERE tabid = 1';
        $value = $this->_adapter->fetchOne($sql);
        return $value;
    }
32448
public function insertGetId(array $values, $sequence = null)
    {
        $this->compileWheres();
        $result = $this->query->insert($values);

        if (0 == (int) $result['errors']) {
            if (isset($values['id'])) {
                return $values['id'];
            }

            // Return id
            return current($result['generated_keys']);
        }
    }
465433
protected function determineLastInsertId(callable $callback, $sequenceName)
	{
		try
		{
			switch($this->driverName)
			{
				case DB::DRIVER_MYSQL:
				case DB::DRIVER_SQLITE:
					return (int)$callback();
				case DB::DRIVER_POSTGRESQL:
					if(is_array($sequenceName))
					{
						$stmt = $this->prepare("SELECT currval(pg_get_serial_sequence(:table, :col))");
						$stmt->bindValue('table', $this->prepareSql($sequenceName[0]));
						$stmt->bindValue('col', $sequenceName[1]);
						$stmt->execute();
							
						return (int)$stmt->fetchNextColumn(0);
					}
					return $callback($this->prepareSql($sequenceName));
				case DB::DRIVER_MYSQL:
					$stmt = $this->prepare("SELECT CAST(COALESCE(SCOPE_IDENTITY(), @@IDENTITY) AS int)");
					$stmt->execute();
						
					return (int)$stmt->fetchNextColumn(0);
			}
		
			return (int)$callback($this->prepareSql($sequenceName));
		}
		catch(\Exception $e)
		{
			throw $this->convertException($e);
		}
	}
1043740
public static function sequenceNextVal($name)
    {
        $sql = null;

        switch (Driver::$name) {
        case "oracle":
            $sql = "select $name.nextval from dual";
            break;
        case "postgresql":
            $sql = "select nextval('$name') as nextval";
            break;
        }

        if ($sql == null) {
            return null;
        }

        $stmt = self::executePrepared($sql);
        $data = $stmt->fetch(\PDO::FETCH_ASSOC);
        $rtn  = null;

        if (!$data) {
            return null;
        }

        $seq_keys = array("nextval", "NEXTVAL");
        foreach ($seq_keys as $seq_key) {
            if (array_key_exists($seq_key, $data)) {
                $rtn = $data[$seq_key];
                break;
            }
        }
        return $rtn;
    }
969504
public function getNextId()
    {
        $sequence = $this->dbHandler->getSequenceName('ezurlalias_ml_incr', 'id');
        /** @var $query \eZ\Publish\Core\Persistence\Database\InsertQuery */
        $query = $this->dbHandler->createInsertQuery();
        $query->insertInto(
            $this->dbHandler->quoteTable('ezurlalias_ml_incr')
        );
        // ezcDatabase does not abstract the "auto increment id"
        // INSERT INTO ezurlalias_ml_incr VALUES(DEFAULT) is not an option due
        // to this mysql bug: http://bugs.mysql.com/bug.php?id=42270
        // as a result we are forced to check which database is currently used
        // to generate the correct SQL query
        // see https://jira.ez.no/browse/EZP-20652
        if ($this->dbHandler->useSequences()) {
            $query->set(
                $this->dbHandler->quoteColumn('id'),
                "nextval('{$sequence}')"
            );
        } else {
            $query->set(
                $this->dbHandler->quoteColumn('id'),
                $query->bindValue(null, null, \PDO::PARAM_NULL)
            );
        }
        $query->prepare()->execute();

        return $this->dbHandler->lastInsertId($sequence);
    }
1138006
public function getLastChild()
	{
		if ( ! $this->hasChildren()) {
			return null;
		}
		$right = $this->getRightValue() - 1;

		$searchCondition = $this->repository->createSearchCondition()
				->rightEqualsTo($right);

		$lastChild = $this->repository->search($searchCondition);
		if ( ! isset($lastChild[0])) {
			$dump = static::dump($this);
			throw new Exception\InvalidStructure("Could not find the last child of {$dump} but it must exist");
		}
		$lastChild = $lastChild[0];
		
		return $lastChild;
	}
654823
public function getLastInsertedId($column = null)
    {
        if (is_string($column)) {
            return $this->getConnection()->lastInsertId($column);
        }

        return $this->getConnection()->lastInsertId();
    }
714762
public function getLastInsertId(string $name = null)
    {
        if (null === $this->pdo) {
            throw new DatabaseException('Not connected: can not retrieve last insert id');
        }

        try {
            return $this->pdo->lastInsertId($name);
        } catch (PDOException $pdoe) {
            throw new DatabaseException($pdoe->getMessage(), $pdoe);
        }
    }
1252517
protected function getGenericSequence($sequence)
    {
        $sql = 'SELECT'.
               '  min_value AS initial_value,'.
               '  increment_by AS increment_size'.
               ' FROM '.$sequence['name'];

        $datas = $this->getConnection()->fetchAssoc($sql);

        return parent::getGenericSequence(
            array(
                'name'           => $sequence['name'],
                'initial_value'  => $datas['initial_value'],
                'increment_size' => $datas['increment_size'],
            )
        );
    }