From: Mike Bayer Date: Tue, 27 Nov 2007 05:44:16 +0000 (+0000) Subject: un-screw up the attribute manager checkin X-Git-Tag: rel_0_4_2~132 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=329703a371d3a2ed356d0f0717b660cc7e975bfa;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git un-screw up the attribute manager checkin --- diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 2e17c2495e..098bd33c89 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -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): diff --git a/test/dialect/mssql.py b/test/dialect/mssql.py index add1d8a5c1..05d9efd786 100755 --- a/test/dialect/mssql.py +++ b/test/dialect/mssql.py @@ -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() diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py index 30f7ea9b24..3828e54968 100644 --- a/test/orm/unitofwork.py +++ b/test/orm/unitofwork.py @@ -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")