def _lockedSql(db, func, *args):
    """
    Ensure write lock on database, otherwise concurrent access can result in
    "schema has changed" errors.
    """
    if not db.inTransaction():
        db.cursor().execute('BEGIN IMMEDIATE')
    return func(*args)