Skip to content

Commit d4d948d

Browse files
committed
add support for loaddata command on Django 1.4 and 1.5
1 parent 752c0ea commit d4d948d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

django_pyodbc/base.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,27 @@ def _cursor(self):
242242

243243
return CursorWrapper(cursor, self.driver_needs_utf8)
244244

245+
def _execute_foreach(self, sql, table_names=None):
246+
cursor = self.cursor()
247+
if not table_names:
248+
table_names = self.introspection.get_table_list(cursor)
249+
for table_name in table_names:
250+
cursor.execute(sql % self.ops.quote_name(table_name))
251+
252+
def check_constraints(self, table_names=None):
253+
self._execute_foreach('ALTER TABLE %s WITH CHECK CHECK CONSTRAINT ALL', table_names)
254+
255+
def disable_constraint_checking(self):
256+
# Windows Azure SQL Database doesn't support sp_msforeachtable
257+
#cursor.execute('EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT ALL"')
258+
self._execute_foreach('ALTER TABLE %s NOCHECK CONSTRAINT ALL')
259+
return True
260+
261+
def enable_constraint_checking(self):
262+
# Windows Azure SQL Database doesn't support sp_msforeachtable
263+
#cursor.execute('EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL"')
264+
self.check_constraints()
265+
245266

246267
class CursorWrapper(object):
247268
"""

0 commit comments

Comments
 (0)