MCPcopy
hub / github.com/django/django / execute_returning_sql

Method execute_returning_sql

django/db/models/sql/compiler.py:2134–2164  ·  view source on GitHub ↗

Execute the specified update and return rows of the returned columns associated with the specified returning_field if the backend supports it.

(self, returning_fields)

Source from the content-addressed store, hash-verified

2132 return row_count
2133
2134 def execute_returning_sql(self, returning_fields):
2135 """
2136 Execute the specified update and return rows of the returned columns
2137 associated with the specified returning_field if the backend supports
2138 it.
2139 """
2140 if self.query.get_related_updates():
2141 raise NotImplementedError(
2142 "Update returning is not implemented for queries with related updates."
2143 )
2144
2145 if (
2146 not returning_fields
2147 or not self.connection.features.can_return_rows_from_update
2148 ):
2149 row_count = self.execute_sql(ROW_COUNT)
2150 return [()] * row_count
2151
2152 self.returning_fields = returning_fields
2153 with self.connection.cursor() as cursor:
2154 sql, params = self.as_sql()
2155 cursor.execute(sql, params)
2156 rows = self.connection.ops.fetch_returned_rows(
2157 cursor, self.returning_params
2158 )
2159 opts = self.query.get_meta()
2160 cols = [field.get_col(opts.db_table) for field in self.returning_fields]
2161 converters = self.get_converters(cols)
2162 if converters:
2163 rows = self.apply_converters(rows, converters)
2164 return list(rows)
2165
2166 def pre_sql_setup(self):
2167 """

Callers 1

_updateMethod · 0.80

Calls 10

execute_sqlMethod · 0.95
as_sqlMethod · 0.95
get_related_updatesMethod · 0.80
cursorMethod · 0.80
get_convertersMethod · 0.80
apply_convertersMethod · 0.80
executeMethod · 0.45
fetch_returned_rowsMethod · 0.45
get_metaMethod · 0.45
get_colMethod · 0.45

Tested by

no test coverage detected