Skip to content

Commit

Permalink
Fixed #19096 - More extendable can_return_id_from_insert
Browse files Browse the repository at this point in the history
RETURNING is an extension of the SQL standard, which is not implemented
the same by all databases. Allow DatabaseOperations.return_insert_id to
return a None to allow for other 3rd party backends with a different
implementation.
  • Loading branch information
manfre committed Oct 9, 2012
1 parent 9a2bcee commit 0e3393d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions django/db/models/sql/compiler.py
Expand Up @@ -897,8 +897,9 @@ def as_sql(self):
col = "%s.%s" % (qn(opts.db_table), qn(opts.pk.column)) col = "%s.%s" % (qn(opts.db_table), qn(opts.pk.column))
result.append("VALUES (%s)" % ", ".join(placeholders[0])) result.append("VALUES (%s)" % ", ".join(placeholders[0]))
r_fmt, r_params = self.connection.ops.return_insert_id() r_fmt, r_params = self.connection.ops.return_insert_id()
result.append(r_fmt % col) if r_fmt:
params += r_params result.append(r_fmt % col)
params += r_params
return [(" ".join(result), tuple(params))] return [(" ".join(result), tuple(params))]
if can_bulk: if can_bulk:
result.append(self.connection.ops.bulk_insert_sql(fields, len(values))) result.append(self.connection.ops.bulk_insert_sql(fields, len(values)))
Expand Down

0 comments on commit 0e3393d

Please sign in to comment.