summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3/operations.py
diff options
context:
space:
mode:
authorgirishsontakke <girishsontakke7@gmail.com>2021-04-06 21:50:31 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-04-07 20:09:56 +0200
commit98abc0c90e0eb7fe3a71cfa360962cf59605f1d3 (patch)
tree3e660de54ec94caa11ab8ef14e98f8cbf231abc0 /django/db/backends/sqlite3/operations.py
parent3f2920ae1d91e67ebf677d407da528c04188384e (diff)
Fixed #32501 -- Added support for returning fields from INSERT statements on SQLite 3.35+.
Diffstat (limited to 'django/db/backends/sqlite3/operations.py')
-rw-r--r--django/db/backends/sqlite3/operations.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py
index c578979777..95484931cf 100644
--- a/django/db/backends/sqlite3/operations.py
+++ b/django/db/backends/sqlite3/operations.py
@@ -76,6 +76,13 @@ class DatabaseOperations(BaseDatabaseOperations):
"""
return "django_date_extract('%s', %s)" % (lookup_type.lower(), field_name)
+ def fetch_returned_insert_rows(self, cursor):
+ """
+ Given a cursor object that has just performed an INSERT...RETURNING
+ statement into a table, return the list of returned data.
+ """
+ return cursor.fetchall()
+
def format_for_duration_arithmetic(self, sql):
"""Do nothing since formatting is handled in the custom function."""
return sql
@@ -365,3 +372,15 @@ class DatabaseOperations(BaseDatabaseOperations):
def insert_statement(self, ignore_conflicts=False):
return 'INSERT OR IGNORE INTO' if ignore_conflicts else super().insert_statement(ignore_conflicts)
+
+ def return_insert_columns(self, fields):
+ # SQLite < 3.35 doesn't support an INSERT...RETURNING statement.
+ if not fields:
+ return '', ()
+ columns = [
+ '%s.%s' % (
+ self.quote_name(field.model._meta.db_table),
+ self.quote_name(field.column),
+ ) for field in fields
+ ]
+ return 'RETURNING %s' % ', '.join(columns), ()