Fixed #33460 -- Used VALUES clause for insert in bulk on SQLite.

SQLite 3.7.11 introduced the ability to use multiple values directly.
SQLite 3.8.8 made multiple values not subject to the
SQLITE_LIMIT_COMPOUND_SELECT (500).
This commit is contained in:
Keryn Knight 2022-01-24 11:36:13 +00:00 committed by Mariusz Felisiak
parent 4ac0bf6acd
commit c27932ec93
1 changed files with 3 additions and 4 deletions

View File

@ -337,10 +337,9 @@ class DatabaseOperations(BaseDatabaseOperations):
return bool(value) if value in (1, 0) else value return bool(value) if value in (1, 0) else value
def bulk_insert_sql(self, fields, placeholder_rows): def bulk_insert_sql(self, fields, placeholder_rows):
return " UNION ALL ".join( placeholder_rows_sql = (', '.join(row) for row in placeholder_rows)
"SELECT %s" % ", ".join(row) values_sql = ', '.join(f'({sql})' for sql in placeholder_rows_sql)
for row in placeholder_rows return f'VALUES {values_sql}'
)
def combine_expression(self, connector, sub_expressions): def combine_expression(self, connector, sub_expressions):
# SQLite doesn't have a ^ operator, so use the user-defined POWER # SQLite doesn't have a ^ operator, so use the user-defined POWER