'Returns a table alias for the given table_name and whether this is a
new alias or not.
If \'create\' is true, a new alias is always created. Otherwise, the
most recently created alias for the table (if one exists) is reused.'

def table_alias(self, table_name, create=False):

    current = self.table_map.get(table_name)
    if ((not create) and current):
        alias = current[0]
        self.alias_refcount[alias] += 1
        return (alias, False)
    if current:
        alias = ('%s%d' % (self.alias_prefix, (len(self.alias_map) + 1)))
        current.append(alias)
    else:
        alias = table_name
        self.table_map[alias] = [alias]
    self.alias_refcount[alias] = 1
    self.tables.append(alias)
    return (alias, True)
