Return the most recent value from the specified sequence in the database.
This is supported only on RDBMS brands that support sequences
(e.g. Oracle, PostgreSQL, DB2).  Other RDBMS brands return null.

@param string $sequenceName
@return string
353060
public function lastSequenceId($sequenceName)
    {
        $this->_connect();

        if (!$this->_isI5) {
            $quotedSequenceName = $this->quoteIdentifier($sequenceName, true);
            $sql = 'SELECT PREVVAL FOR ' . $quotedSequenceName . ' AS VAL FROM SYSIBM.SYSDUMMY1';
        } else {
            $quotedSequenceName = $sequenceName;
            $sql = 'SELECT PREVVAL FOR ' . $this->quoteIdentifier($sequenceName, true) . ' AS VAL FROM QSYS2.QSQPTABL';
        }

        $value = $this->fetchOne($sql);
        return (string) $value;
    }
502217
public function getSqlFileByName($fileName)
    {
        $sqlFinder = $this->getFinder();

        $files = $sqlFinder->files()
            ->in($this->sqlFilesDir)
            ->name($fileName)
        ;

        if ($files->count() !== 1) {
            throw new RuntimeException('cannot find File:' . $fileName);
        }

        foreach ($files as $file){
            return $file;
        }
    }
98876
public function getLastByKey($key)
    {
        if (!isset($this->keyList[$key])) {
            return null;
        }
        
        // returns the last entry
        return $this->keyList[$key]->top();
    }
988263
public function getPropertyByQueryName($queryName)
    {
        return isset($this->propertiesByQueryName[$queryName]) ? $this->propertiesByQueryName[$queryName] : null;
    }
393397
private function _oracleSequenceExists($name)
    {
        $escape = Driver::$escape_char;
        $sql    = "select count(sequence_name) as $escape"."CNT"."$escape from user_sequences where sequence_name='$name' or sequence_name='".strtolower($name)."' or sequence_name='".strtoupper($name)."'";
        $stmt   = self::query($sql);
        $rst    = $stmt->fetch(\PDO::FETCH_ASSOC);
        $rtn    = intval($rst["CNT"]) > 0;
        self::closeCursor($stmt);
        return $rtn;
    }
927331
private Long getSequence(String sequenceName)
    {
        Long result = null;
        // now lookup the sequence map for calling DB
        Map mapForDB = (Map) sequencesDBMap.get(getBrokerForClass()
                .serviceConnectionManager().getConnectionDescriptor().getJcdAlias());
        if(mapForDB != null)
        {
            result = (Long) mapForDB.get(sequenceName);
        }
        return result;
    }
1136475
public function getResetSequenceSQL($table) {

        if (is_string($table)) {
            $tablename = $table;
            $xmldb_table = new xmldb_table($tablename);
        } else {
            $tablename = $table->getName();
            $xmldb_table = $table;
        }
        // From http://www.acs.ilstu.edu/docs/oracle/server.101/b10759/statements_2011.htm
        $value = (int)$this->mdb->get_field_sql('SELECT MAX(id) FROM {'.$tablename.'}');
        $value++;

        $seqname = $this->getSequenceFromDB($xmldb_table);

        if (!$seqname) {
            // Fallback, seqname not found, something is wrong. Inform and use the alternative getNameForObject() method
            $seqname = $this->getNameForObject($table, 'id', 'seq');
        }

        return array ("DROP SEQUENCE $seqname",
                      "CREATE SEQUENCE $seqname START WITH $value INCREMENT BY 1 NOMAXVALUE CACHE $this->sequence_cache_size");
    }
250750
protected function readUntilSequence($sequence) {
        $buffer = '';

        // Optimization for reading larger blocks faster.
        $first = substr($sequence, 0, 1);
        while ($this->scanner->current() !== false) {
            $buffer .= $this->scanner->charsUntil($first);

            // Stop as soon as we hit the stopping condition.
            if ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))) {
                return $buffer;
            }
            $buffer .= $this->scanner->current();
            $this->scanner->next();
        }

        // If we get here, we hit the EOF.
        $this->parseError("Unexpected EOF during text read.");
        return $buffer;
    }
495455
public function insertReturnId(string $table, array $map, string $sequenceName = '')
    {
        if ($this->dbEngine === 'pgsql') {
            throw new \Exception(
                'Do not use insertReturnId() with PostgreSQL. Use insertGet() instead, ' .
                'with an explicit column name rather than a sequence name.'
            );
        }
        if (!$this->insert($table, $map)) {
            throw new Issues\QueryError('Could not insert a new row into ' . $table . '.');
        }
        if ($sequenceName) {
            return $this->lastInsertId($sequenceName);
        }
        return $this->lastInsertId();
    }
1027009
public function lastInsertId($sequenceName = null)
    {
        if (isset($this->lastInsertedIds[$sequenceName])) {
            $lastInsertId = $this->lastInsertedIds[$sequenceName];
            unset($this->lastInsertedIds[$sequenceName]);

            return $lastInsertId;
        }

        return $this->connection->lastInsertId($sequenceName);
    }
633393
protected static function getSequenceCurval( array $sequences, Pg $db )
    {

        // anything to do
        if( !$sequences ) {
            return array();
        }

        // sequence components
        foreach( $sequences as $key => &$sequence ) {

            $sequence = sprintf(
                "currval('%s'::regclass) as %s",
                $sequence,
                Query::quoteIdentifier( $key )
            );

        }
        $sequences = implode(', ', $sequences);

        return $db->query( new Query( "SELECT {$sequences};" ) )->fetchSingle( Result::FLATTEN_PREVENT );

    }
536905
final public static function getDbInstance(string $databaseName = '#none'):\PDO
    {
        if (self::$co_instance == null) {
            new self($databaseName);
        }
        return (self::$co_instance);
    }
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);
        }
    }
1050922
public function getDbName ()
		{
			if ($this->db->getDriverName() == 'mysql')
			{
				preg_match("/dbname=([^;]*)/", $this->db->dsn, $match);
				if (isset($match[ 1 ]))
					return $match[ 1 ];
			}

			return null;
		}
1035145
private function _postgresqlSequenceExists($name)
    {
        $escape = Driver::$escape_char;
        $sql    = "select count(*) as {$escape}CNT{$escape} from information_schema.sequences where sequence_name = '$name'";
        $stmt   = self::query($sql);
        $rst    = $stmt->fetch(\PDO::FETCH_ASSOC);
        $rtn    = intval($rst["CNT"]) > 0;
        self::closeCursor($stmt);
        return $rtn;
    }
914643
public function getTableByPhpName($phpName)
    {
        if (isset($this->tablesByPhpName[$phpName])) {
            return $this->tablesByPhpName[$phpName];
        }

        return null; // just to be explicit
    }
340064
public function getNextValue(string $sequenceName): int
    {
        $sequenceValue = $this->rawCollection()->findOneAndUpdate(
            ['_id' => $sequenceName],
            ['$inc' => ['seq' => 1]],
            ['upsert' => true]
        );

        if ($sequenceValue) {
            $_id = $sequenceValue->seq + 1;
        }

        return $_id ?? 1;
    }