]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
un-screw up the attribute manager checkin
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 27 Nov 2007 05:44:16 +0000 (05:44 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 27 Nov 2007 05:44:16 +0000 (05:44 +0000)
lib/sqlalchemy/databases/mssql.py
test/dialect/mssql.py
test/orm/unitofwork.py

index 2e17c2495e499d05b30956fcb51e63a362e0a7a0..098bd33c8972a4eb9bbd9510a8d447a2d5c1b667 100644 (file)
@@ -877,6 +877,8 @@ class MSSQLCompiler(compiler.DefaultCompiler):
         s = select._distinct and "DISTINCT " or ""
         if select._limit:
             s += "TOP %s " % (select._limit,)
+        if select._offset:
+            raise exceptions.InvalidRequestError('MSSQL does not support LIMIT with an offset')
         return s
 
     def limit_clause(self, select):    
@@ -949,36 +951,6 @@ class MSSQLCompiler(compiler.DefaultCompiler):
         else:
             return ""
 
-    def visit_select(self, select, **kwargs):
-        """Look for OFFSET in a select statement, and if so tries to wrap 
-        it in a subquery with ``row_number()`` criterion.
-        """
-
-        if not getattr(select, '_mssql_visit', None) and select._offset is not None:
-            # to use ROW_NUMBER(), an ORDER BY is required.
-            orderby = self.process(select._order_by_clause)
-            if not orderby:
-                raise exceptions.InvalidRequestError("OFFSET in MS-SQL requires an ORDER BY clause")
-                
-            oldselect = select
-            select = select.column(sql.literal_column("ROW_NUMBER() OVER (ORDER BY %s)" % orderby).label("mssql_rn")).order_by(None)
-            select._mssql_visit = True
-
-            select_alias = select.alias()
-            limitselect = sql.select([c.label(list(c.proxies)[0].name) for c in select_alias.c if c.key!='mssql_rn'])
-            #limitselect._order_by_clause = select._order_by_clause
-            select._order_by_clause = expression.ClauseList(None)
-
-            if select._offset is not None:
-                limitselect.append_whereclause("mssql_rn>%d" % select._offset)
-                if select._limit is not None:
-                    limitselect.append_whereclause("mssql_rn<=%d" % (select._limit + select._offset))
-                    select._limit = None
-            return self.process(limitselect, **kwargs)
-        else:
-            return compiler.DefaultCompiler.visit_select(self, select, **kwargs)
-
-
 
 class MSSQLSchemaGenerator(compiler.SchemaGenerator):
     def get_column_specification(self, column, **kwargs):
index add1d8a5c16d0d360618df56ebeb6a0e9e1b46dd..05d9efd7865bb4404139705f38a4210617c4f7c0 100755 (executable)
@@ -52,38 +52,6 @@ class CompileTest(SQLCompileTest):
         m = MetaData()
         t = Table('sometable', m, Column('col1', Integer), Column('col2', Integer))
         self.assert_compile(select([func.max(t.c.col1)]), "SELECT max(sometable.col1) AS max_1 FROM sometable")
-
-    def test_limit(self):
-        t = table('sometable', column('col1'), column('col2'))
-
-        s = select([t]).limit(10).offset(20).order_by(t.c.col1).apply_labels()
-
-        self.assert_compile(s, "SELECT anon_1.sometable_col1 AS sometable_col1, anon_1.sometable_col2 AS sometable_col2 FROM (SELECT sometable.col1 AS sometable_col1, sometable.col2 AS sometable_col2, "
-            "ROW_NUMBER() OVER (ORDER BY sometable.col1) AS mssql_rn FROM sometable) AS anon_1 WHERE mssql_rn>20 AND mssql_rn<=30"
-        )
-
-        s = select([t]).limit(10).offset(20).order_by(t.c.col1)
-
-        self.assert_compile(s, "SELECT anon_1.col1 AS col1, anon_1.col2 AS col2 FROM (SELECT sometable.col1 AS col1, sometable.col2 AS col2, "
-            "ROW_NUMBER() OVER (ORDER BY sometable.col1) AS mssql_rn FROM sometable) AS anon_1 WHERE mssql_rn>20 AND mssql_rn<=30"
-        )
-
-        s = select([s.c.col1, s.c.col2])
-
-        self.assert_compile(s, "SELECT col1, col2 FROM (SELECT anon_1.col1 AS col1, anon_1.col2 AS col2 FROM "
-            "(SELECT sometable.col1 AS col1, sometable.col2 AS col2, ROW_NUMBER() OVER (ORDER BY sometable.col1) AS mssql_rn FROM sometable) AS anon_1 "
-            "WHERE mssql_rn>20 AND mssql_rn<=30)")
-
-        # testing this twice to ensure oracle doesn't modify the original statement 
-        self.assert_compile(s, "SELECT col1, col2 FROM (SELECT anon_1.col1 AS col1, anon_1.col2 AS col2 FROM "
-            "(SELECT sometable.col1 AS col1, sometable.col2 AS col2, ROW_NUMBER() OVER (ORDER BY sometable.col1) AS mssql_rn FROM sometable) AS anon_1 "
-            "WHERE mssql_rn>20 AND mssql_rn<=30)")
-
-        s = select([t]).limit(10).offset(20).order_by(t.c.col2)
-
-        self.assert_compile(s, "SELECT anon_1.col1 AS col1, anon_1.col2 AS col2 FROM (SELECT sometable.col1 AS col1, "
-            "sometable.col2 AS col2, ROW_NUMBER() OVER (ORDER BY sometable.col2) AS mssql_rn FROM sometable) AS anon_1 WHERE mssql_rn>20 AND mssql_rn<=30")
-
         
 if __name__ == "__main__":
     testbase.main()
index 30f7ea9b24478cf11a4353b98ea5abfc59d02ac4..3828e54968c06a962adaf188a6a9554dc5fbcf9a 100644 (file)
@@ -234,7 +234,7 @@ class UnicodeSchemaTest(ORMTest):
         Session.clear()
 
     @testing.supported('sqlite', 'postgres')
-    def dont_test_inheritance_mapping(self):
+    def test_inheritance_mapping(self):
         class A(fixtures.Base):pass
         class B(A):pass
         mapper(A, t1, polymorphic_on=t1.c.type, polymorphic_identity='a')
@@ -1079,7 +1079,6 @@ class SaveTest(ORMTest):
         Session.close()
         l = Session.query(AddressUser).selectone()
         self.assert_(l.user_id == au.user_id and l.address_id == au.address_id)
-        print "TEST INHERITS DONE"
         
     def test_deferred(self):
         """test deferred column operations"""
@@ -1119,7 +1118,7 @@ class SaveTest(ORMTest):
     # why no support on oracle ?  because oracle doesn't save
     # "blank" strings; it saves a single space character. 
     @testing.unsupported('oracle') 
-    def dont_test_dont_update_blanks(self):
+    def test_dont_update_blanks(self):
         mapper(User, users)
         u = User()
         u.user_name = ""
@@ -1172,7 +1171,7 @@ class SaveTest(ORMTest):
         u = Session.get(User, id)
         assert u.user_name == 'imnew'
     
-    def dont_test_history_get(self):
+    def test_history_get(self):
         """tests that the history properly lazy-fetches data when it wasnt otherwise loaded"""
         mapper(User, users, properties={
             'addresses':relation(Address, cascade="all, delete-orphan")