Permalink
Browse files

fix bulk_insert_sql error in Django 1.9+

error msg:
  TypeError: can't multiply sequence by non-int of type 'tuple'
  in bulk_insert_sql
  • Loading branch information...
Robert Lu Robert Lu
Robert Lu authored and Robert Lu committed Feb 27, 2017
1 parent 93c7b38 commit 8dab00b9df9d4e1c6a2b69323c0a5dbc5aac030d
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/mysql/connector/django/operations.py
@@ -234,9 +234,15 @@ def value_to_db_time(self, value):
def max_name_length(self):
return 64
- def bulk_insert_sql(self, fields, num_values):
- items_sql = "({0})".format(", ".join(["%s"] * len(fields)))
- return "VALUES " + ", ".join([items_sql] * num_values)
+ def bulk_insert_sql(self, fields, placeholder_rows):
+ if django.VERSION < (1, 9):
+ num_values = placeholder_rows
+ items_sql = "({0})".format(", ".join(["%s"] * len(fields)))
+ return "VALUES " + ", ".join([items_sql] * num_values)
+ else:
+ placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
+ values_sql = ", ".join("(%s)" % sql for sql in placeholder_rows_sql)
+ return "VALUES " + values_sql
if django.VERSION < (1, 8):
def year_lookup_bounds(self, value):

0 comments on commit 8dab00b

Please sign in to comment.