Fixed #19096 -- Made can_return_id_from_insert more extendable
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.
This commit is contained in:
parent
252cd271e8
commit
c2150d4d2c
|
@ -897,6 +897,9 @@ class SQLInsertCompiler(SQLCompiler):
|
||||||
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()
|
||||||
|
# Skip empty r_fmt to allow subclasses to customize behaviour for
|
||||||
|
# 3rd party backends. Refs #19096.
|
||||||
|
if r_fmt:
|
||||||
result.append(r_fmt % col)
|
result.append(r_fmt % col)
|
||||||
params += r_params
|
params += r_params
|
||||||
return [(" ".join(result), tuple(params))]
|
return [(" ".join(result), tuple(params))]
|
||||||
|
|
Loading…
Reference in New Issue