Commits

adamv committed 456d8f6

Preliminary fix for issue 11 regression.

  • Participants
  • Parent commits 9c86520

Comments (0)

Files changed (2)

src/sqlserver_ado/base.py

 
 class DatabaseFeatures(BaseDatabaseFeatures):
     supports_tablespaces = True
-    #uses_custom_query_class = True
+    uses_custom_query_class = True
 
 class DatabaseOperations(BaseDatabaseOperations):
     def date_extract_sql(self, lookup_type, field_name):

src/sqlserver_ado/query.py

 # This seems fragile, but less so than relying on patches against
 # Django's guts.
 def query_class(QueryClass, Database):
-	"""
-	Returns a custom django.db.models.sql.query.Query subclass that is
-	appropriate for MS SQL Server.
-	"""
-	class SqlServerQuery(QueryClass):
-		def __init__(self, *args, **kwargs):
-			super(SqlServerQuery, self).__init__(*args, **kwargs)
+    """
+    Returns a custom django.db.models.sql.query.Query subclass that is
+    appropriate for MS SQL Server.
+    """
+    class SqlServerQuery(QueryClass):
+        def __init__(self, *args, **kwargs):
+            super(SqlServerQuery, self).__init__(*args, **kwargs)
+            
+            # If we are an insert query, wrap "as_sql"
+            if self.__class__.__name__ == "InsertQuery":
+                self._parent_as_sql = self.as_sql
+                self.as_sql = self._insert_as_sql
+
+        def _insert_as_sql(self, *args, **kwargs):
+            meta = self.model._meta
+            quoted_table = self.connection.ops.quote_name(meta.db_table)
+            # Get (sql,params) from original InsertQuery.as_sql
+            sql, params = self._parent_as_sql(*args,**kwargs)
+
+            if meta.pk.attname in self.columns:
+                sql = "SET IDENTITY_INSERT %s ON;%s;SET IDENTITY_INSERT %s OFF" % \
+                    (quoted_table, sql, quoted_table)
 			
-			# If we are an insert query, wrap "as_sql"
-			if self.__class__.__name__ == "InsertQuery":
-				self.as_sql = self._insert_as_sql
-		
-		def _insert_as_sql(self, *args, **kwargs):
-			meta = self.model._meta
-			quoted_table = self.connection.ops.quote_name(meta.db_table)
-			# Get (sql,params) from original InsertQuery.as_sql
-			sql, params = super(SqlServerQuery, self).as_sql(*args,**kwargs)
-			
-			if meta.pk.attname in self.columns:
-				sql = "SET IDENTITY_INSERT %s ON;%s;SET IDENTITY_INSERT %s OFF" % \
-					(quoted_table, sql, quoted_table)
-			
-			return sql, params
+            return sql, params
 
-	return SqlServerQuery
+    return SqlServerQuery