Skip to content

Commit

Permalink
fix issue avidal#7
Browse files Browse the repository at this point in the history
  • Loading branch information
michiya committed Jun 6, 2013
1 parent b7beb02 commit bce251f
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions django_pyodbc/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def as_sql(self):
result.append("VALUES (%s)" % ", ".join(placeholders[0]))
return [(" ".join(result), tuple(params))]

sql, params = [
items = [
(" ".join(result + ["VALUES (%s)" % ", ".join(p)]), vals)
for p, vals in zip(placeholders, params)
]
Expand All @@ -323,16 +323,19 @@ def as_sql(self):
if meta.has_auto_field:
# db_column is None if not explicitly specified by model field
auto_field_column = meta.auto_field.db_column or meta.auto_field.column

if auto_field_column in columns:
quoted_table = self.connection.ops.quote_name(meta.db_table)
# If there are no fields specified in the insert..
if not has_fields:
sql = "INSERT INTO %s DEFAULT VALUES" % quoted_table
else:
sql = "SET IDENTITY_INSERT %s ON;\n%s;\nSET IDENTITY_INSERT %s OFF" % \
(quoted_table, sql, quoted_table)
return sql, params
out = []
for sql, params in items:
if auto_field_column in columns:
quoted_table = self.connection.ops.quote_name(meta.db_table)
# If there are no fields specified in the insert..
if not has_fields:
sql = "INSERT INTO %s DEFAULT VALUES" % quoted_table
else:
sql = "SET IDENTITY_INSERT %s ON;\n%s;\nSET IDENTITY_INSERT %s OFF" % \
(quoted_table, sql, quoted_table)
out.append([sql, params])
items = out
return items


class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):
Expand Down

0 comments on commit bce251f

Please sign in to comment.