Pheasant\Database\Mysqli\SequencePool::_lockSequence PHP Method

_lockSequence() private method

Locks the sequence, creates it if needed and returns the current value
private _lockSequence ( $sequence )
    private function _lockSequence($sequence)
    {
        $result = $this->_connection->execute("SELECT id FROM sequences WHERE name=? FOR UPDATE", $sequence);
        switch (count($result)) {
            case 0:
                // sequence not in table; insert and use startId value
                $this->_connection->execute("INSERT INTO sequences VALUES (?,?)", $sequence, $this->_startId);
                $id = $this->_startId;
                break;
            case 1:
                // sequence already in table; remember its current ID
                $id = $result[0]['id'];
                break;
            default:
                // multiple rows for sequence; bad
                throw new \Pheasant\Exception("Multiple rows exist for sequence '{$sequence}'");
                break;
        }
        return $id;
    }