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)
| 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 | """ |
no test coverage detected