'Allocate a synthetic identifier by updating a table.'

def _new_id_update(sql, key):

    while True:
        row = sql.selectrow(('SELECT    nextid    FROM    %ssequences    WHERE    sequence_key    =    ?' % sql.prefix), (key,))
        if (row is None):
            raise Exception(('Sequence    %s    does    not    exist' % key))
        ret = row[0]
        sql.sql(('UPDATE    %ssequences    SET    nextid    =    nextid    +    1    WHERE    sequence_key    =    ?    AND    nextid    =    ?' % sql.prefix), (key, ret))
        if (sql.cursor().rowcount == 1):
            return ret
        sql.log.info(('Contention    on    %ssequences    %s:%d' % sql.prefix), key, ret)
