'Add data to the various extra_* attributes for user-created additions
to the query.'

def add_extra(self, select, select_params, where, params, tables, order_by):

    if select:
        select_pairs = OrderedDict()
        if select_params:
            param_iter = iter(select_params)
        else:
            param_iter = iter([])
        for (name, entry) in select.items():
            entry = force_text(entry)
            entry_params = []
            pos = entry.find('%s')
            while (pos != (-1)):
                if ((pos == 0) or (entry[(pos - 1)] != '%')):
                    entry_params.append(next(param_iter))
                pos = entry.find('%s', (pos + 2))
            select_pairs[name] = (entry, entry_params)
        self.extra.update(select_pairs)
    if (where or params):
        self.where.add(ExtraWhere(where, params), AND)
    if tables:
        self.extra_tables += tuple(tables)
    if order_by:
        self.extra_order_by = order_by
