| 1 |
def raw_cte_sql(sql, params, refs): |
| 2 |
"""Raw CTE SQL |
| 3 |
|
| 4 |
:param sql: SQL query (string). |
| 5 |
:param params: List of bind parameters. |
| 6 |
:param refs: Dict of output fields: `{"name": <Field instance>}`. |
| 7 |
:returns: Object that can be passed to `With`. |
| 8 |
""" |
| 9 |
|
| 10 |
class raw_cte_ref: |
| 11 |
def __init__(self, output_field): |
| 12 |
self.output_field = output_field |
| 13 |
|
| 14 |
def get_source_expressions(self): |
| 15 |
return [] |
| 16 |
|
| 17 |
class raw_cte_compiler: |
| 18 |
|
| 19 |
def __init__(self, connection): |
| 20 |
self.connection = connection |
| 21 |
|
| 22 |
def as_sql(self): |
| 23 |
return sql, params |
| 24 |
|
| 25 |
def quote_name(self, name): |
| 26 |
return self.connection.ops.quote_name(name) |
| 27 |
|
| 28 |
# Name used by Django < 6.1. |
| 29 |
quote_name_unless_alias = quote_name |
| 30 |
|
| 31 |
class raw_cte_queryset: |
| 32 |
class query: |
| 33 |
annotations = {} |
| 34 |
|
| 35 |
@staticmethod |
| 36 |
def get_compiler(connection, *, elide_empty=None): |
| 37 |
return raw_cte_compiler(connection) |
| 38 |
|
| 39 |
@staticmethod |
| 40 |
def resolve_ref(name): |
| 41 |
return raw_cte_ref(refs[name]) |
| 42 |
|
| 43 |
@classmethod |
| 44 |
def resolve_expression(cls, *args, **kwargs): |
| 45 |
return cls |
| 46 |
|
| 47 |
return raw_cte_queryset |