Refs #31403 -- Made SQLInsertCompiler.execute_sql() always return an iterable of rows.
List of tuples.
This commit is contained in:
parent
00ff7a44de
commit
c06d7c9239
|
@ -253,6 +253,7 @@ END;
|
||||||
return " DEFERRABLE INITIALLY DEFERRED"
|
return " DEFERRABLE INITIALLY DEFERRED"
|
||||||
|
|
||||||
def fetch_returned_insert_columns(self, cursor, returning_params):
|
def fetch_returned_insert_columns(self, cursor, returning_params):
|
||||||
|
columns = []
|
||||||
for param in returning_params:
|
for param in returning_params:
|
||||||
value = param.get_value()
|
value = param.get_value()
|
||||||
if value is None or value == []:
|
if value is None or value == []:
|
||||||
|
@ -264,7 +265,8 @@ END;
|
||||||
'https://code.djangoproject.com/ticket/28859).'
|
'https://code.djangoproject.com/ticket/28859).'
|
||||||
)
|
)
|
||||||
# cx_Oracle < 7 returns value, >= 7 returns list with single value.
|
# cx_Oracle < 7 returns value, >= 7 returns list with single value.
|
||||||
yield value[0] if isinstance(value, list) else value
|
columns.append(value[0] if isinstance(value, list) else value)
|
||||||
|
return tuple(columns)
|
||||||
|
|
||||||
def field_cast_sql(self, db_type, internal_type):
|
def field_cast_sql(self, db_type, internal_type):
|
||||||
if db_type and db_type.endswith('LOB'):
|
if db_type and db_type.endswith('LOB'):
|
||||||
|
|
|
@ -889,8 +889,9 @@ class Model(metaclass=ModelBase):
|
||||||
|
|
||||||
returning_fields = meta.db_returning_fields
|
returning_fields = meta.db_returning_fields
|
||||||
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
|
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
|
||||||
for result, field in zip(results, returning_fields):
|
if results:
|
||||||
setattr(self, field.attname, result)
|
for value, field in zip(results[0], returning_fields):
|
||||||
|
setattr(self, field.attname, value)
|
||||||
return updated
|
return updated
|
||||||
|
|
||||||
def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update):
|
def _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update):
|
||||||
|
|
|
@ -1249,15 +1249,11 @@ class QuerySet:
|
||||||
bulk_return = connections[self.db].features.can_return_rows_from_bulk_insert
|
bulk_return = connections[self.db].features.can_return_rows_from_bulk_insert
|
||||||
for item in [objs[i:i + batch_size] for i in range(0, len(objs), batch_size)]:
|
for item in [objs[i:i + batch_size] for i in range(0, len(objs), batch_size)]:
|
||||||
if bulk_return and not ignore_conflicts:
|
if bulk_return and not ignore_conflicts:
|
||||||
inserted_columns = self._insert(
|
inserted_rows.extend(self._insert(
|
||||||
item, fields=fields, using=self.db,
|
item, fields=fields, using=self.db,
|
||||||
returning_fields=self.model._meta.db_returning_fields,
|
returning_fields=self.model._meta.db_returning_fields,
|
||||||
ignore_conflicts=ignore_conflicts,
|
ignore_conflicts=ignore_conflicts,
|
||||||
)
|
))
|
||||||
if isinstance(inserted_columns, list):
|
|
||||||
inserted_rows.extend(inserted_columns)
|
|
||||||
else:
|
|
||||||
inserted_rows.append(inserted_columns)
|
|
||||||
else:
|
else:
|
||||||
self._insert(item, fields=fields, using=self.db, ignore_conflicts=ignore_conflicts)
|
self._insert(item, fields=fields, using=self.db, ignore_conflicts=ignore_conflicts)
|
||||||
return inserted_rows
|
return inserted_rows
|
||||||
|
|
|
@ -1385,10 +1385,10 @@ class SQLInsertCompiler(SQLCompiler):
|
||||||
return self.connection.ops.fetch_returned_insert_rows(cursor)
|
return self.connection.ops.fetch_returned_insert_rows(cursor)
|
||||||
if self.connection.features.can_return_columns_from_insert:
|
if self.connection.features.can_return_columns_from_insert:
|
||||||
assert len(self.query.objs) == 1
|
assert len(self.query.objs) == 1
|
||||||
return self.connection.ops.fetch_returned_insert_columns(cursor, self.returning_params)
|
return [self.connection.ops.fetch_returned_insert_columns(cursor, self.returning_params)]
|
||||||
return [self.connection.ops.last_insert_id(
|
return [(self.connection.ops.last_insert_id(
|
||||||
cursor, self.query.get_meta().db_table, self.query.get_meta().pk.column
|
cursor, self.query.get_meta().db_table, self.query.get_meta().pk.column
|
||||||
)]
|
),)]
|
||||||
|
|
||||||
|
|
||||||
class SQLDeleteCompiler(SQLCompiler):
|
class SQLDeleteCompiler(SQLCompiler):
|
||||||
|
|
Loading…
Reference in New Issue