def bayesdb_colno_to_variable_names(bdb, population_id, generator_id):
    """Return a dictionary that maps column number to variable name in population."""
    cursor = bdb.sql_execute('''
        SELECT colno, name FROM bayesdb_variable
            WHERE population_id = ?
                AND (generator_id IS NULL OR generator_id = ?)
    ''', (population_id, generator_id))
    return {colno: name for (colno, name) in cursor}