summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2011-09-09 19:22:28 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2011-09-09 19:22:28 +0000
commit7deb25b8dd5aa1ed02b5e30cbc67cd1fb0c3d6e6 (patch)
tree09ed3208f309d71b5710b8287bccdb92ddf40c58 /django/db/backends/sqlite3
parente55bbf4c3c42b17d52c21bc3a460b4981fdc190c (diff)
Fixed #7596. Added Model.objects.bulk_create, and make use of it in several places. This provides a performance benefit when inserting multiple objects. THanks to Russ for the review, and Simon Meers for the MySQl implementation.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16739 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/sqlite3')
-rw-r--r--django/db/backends/sqlite3/base.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index e3c12f7583..b45c0fb935 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -58,6 +58,8 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_unspecified_pk = True
supports_1000_query_parameters = False
supports_mixed_date_datetime_comparisons = False
+ has_bulk_insert = True
+ can_combine_inserts_with_and_without_auto_increment_pk = True
def _supports_stddev(self):
"""Confirm support for STDDEV and related stats functions
@@ -106,7 +108,7 @@ class DatabaseOperations(BaseDatabaseOperations):
return ""
def pk_default_value(self):
- return 'NULL'
+ return "NULL"
def quote_name(self, name):
if name.startswith('"') and name.endswith('"'):
@@ -154,6 +156,14 @@ class DatabaseOperations(BaseDatabaseOperations):
# No field, or the field isn't known to be a decimal or integer
return value
+ def bulk_insert_sql(self, fields, num_values):
+ res = []
+ res.append("SELECT %s" % ", ".join(
+ "%%s AS %s" % self.quote_name(f.column) for f in fields
+ ))
+ res.extend(["UNION SELECT %s" % ", ".join(["%s"] * len(fields))] * (num_values - 1))
+ return " ".join(res)
+
class DatabaseWrapper(BaseDatabaseWrapper):
vendor = 'sqlite'
# SQLite requires LIKE statements to include an ESCAPE clause if the value