Commits

adamv committed 15f2c4c

Fix for issue 43.

Comments (0)

Files changed (1)

source/sqlserver_ado/query.py

             super(SqlServerQuery, self).__init__(*args, **kwargs)
 
             # If we are an insert query, wrap "as_sql"
-            if self.__class__.__name__ == "InsertQuery":
+            # Import here to avoid circular dependency
+            from django.db.models.sql.subqueries import InsertQuery
+            if isinstance(self, InsertQuery):
                 self._parent_as_sql = self.as_sql
                 self.as_sql = self._insert_as_sql
 
             
             # Get out of the way if we're not a select query or there's no limiting involved.
             check_limits = with_limits and (self.low_mark or self.high_mark is not None)
-            if self.__class__.__name__ != 'SqlServerQuery' or not check_limits:
+            if not isinstance(self, SqlServerQuery) or not check_limits:
                 return super(SqlServerQuery, self).as_sql(with_limits, with_col_aliases)
 
             raw_sql, fields = super(SqlServerQuery, self).as_sql(False, with_col_aliases)
                  % (outer_fields, order, inner_select, where_row_num)
             
             return sql, fields
-
+ 
         def _alias_columns(self, sql):
             """Return tuple of SELECT and FROM clauses, aliasing duplicate column names."""
             qn = self.connection.ops.quote_name
         
             outer = list()
             inner = list()
-
             names_seen = list()
             
             select_list, from_clause = _break(sql, ' FROM [')