Add data to the various extra_* attributes for user-created additions to the query.
(self, select, select_params, where, params, tables, order_by)
| 2461 | self.select_related = field_dict |
| 2462 | |
| 2463 | def add_extra(self, select, select_params, where, params, tables, order_by): |
| 2464 | """ |
| 2465 | Add data to the various extra_* attributes for user-created additions |
| 2466 | to the query. |
| 2467 | """ |
| 2468 | if select: |
| 2469 | # We need to pair any placeholder markers in the 'select' |
| 2470 | # dictionary with their parameters in 'select_params' so that |
| 2471 | # subsequent updates to the select dictionary also adjust the |
| 2472 | # parameters appropriately. |
| 2473 | select_pairs = {} |
| 2474 | if select_params: |
| 2475 | param_iter = iter(select_params) |
| 2476 | else: |
| 2477 | param_iter = iter([]) |
| 2478 | for name, entry in select.items(): |
| 2479 | self.check_alias(name) |
| 2480 | entry = str(entry) |
| 2481 | entry_params = [] |
| 2482 | pos = entry.find("%s") |
| 2483 | while pos != -1: |
| 2484 | if pos == 0 or entry[pos - 1] != "%": |
| 2485 | entry_params.append(next(param_iter)) |
| 2486 | pos = entry.find("%s", pos + 2) |
| 2487 | select_pairs[name] = (entry, entry_params) |
| 2488 | self.extra.update(select_pairs) |
| 2489 | if where or params: |
| 2490 | self.where.add(ExtraWhere(where, params), AND) |
| 2491 | if tables: |
| 2492 | self.extra_tables += tuple(tables) |
| 2493 | if order_by: |
| 2494 | self.extra_order_by = order_by |
| 2495 | |
| 2496 | def clear_deferred_loading(self): |
| 2497 | """Remove any fields from the deferred loading set.""" |
no test coverage detected