From 62410adeb9f6a0e01de35680ff77cc15ae994995 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 12 Aug 2007 21:36:33 +0000 Subject: [PATCH] - fixed compiler bug in mssql - marked as unsupported for mssql all two-phase and nested transcation tests - marked as unsupported for mssql various transactional/session tests which require two connections looking at uncommitted/external data at the same time (ms-sql cant handle it) - put better explicit closeout step in unitofwork.py tests to appease ms-sqls hard locking --- lib/sqlalchemy/ansisql.py | 5 ++++- lib/sqlalchemy/databases/mssql.py | 2 +- test/dialect/alltests.py | 1 + test/dialect/mssql.py | 34 +++++++++++++++++++++++++++++++ test/engine/transaction.py | 6 +++--- test/orm/unitofwork.py | 21 ++++++++++++------- 6 files changed, 57 insertions(+), 12 deletions(-) create mode 100755 test/dialect/mssql.py diff --git a/lib/sqlalchemy/ansisql.py b/lib/sqlalchemy/ansisql.py index 1dec5ede0f..8c7e6bb1cf 100644 --- a/lib/sqlalchemy/ansisql.py +++ b/lib/sqlalchemy/ansisql.py @@ -225,7 +225,10 @@ class ANSICompiler(engine.Compiled, sql.ClauseVisitor): if stack: self.stack.append(stack) try: - return self.traverse_single(obj, **kwargs) + x = self.traverse_single(obj, **kwargs) + if x is None: + raise "hi " + repr(obj) + return x finally: if stack: self.stack.pop(-1) diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 405b97617a..9ec0fbbc38 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -897,7 +897,7 @@ class MSSQLCompiler(ansisql.ANSICompiler): } def visit_function(self, func): func.name = self.function_rewrites.get(func.name, func.name) - super(MSSQLCompiler, self).visit_function(func) + return super(MSSQLCompiler, self).visit_function(func) def for_update_clause(self, select): # "FOR UPDATE" is only allowed on "DECLARE CURSOR" which SQLAlchemy doesn't use diff --git a/test/dialect/alltests.py b/test/dialect/alltests.py index 8900736259..aeb754d5f8 100644 --- a/test/dialect/alltests.py +++ b/test/dialect/alltests.py @@ -6,6 +6,7 @@ def suite(): 'dialect.mysql', 'dialect.postgres', 'dialect.oracle', + 'dialect.mssql', ) alltests = unittest.TestSuite() for name in modules_to_test: diff --git a/test/dialect/mssql.py b/test/dialect/mssql.py new file mode 100755 index 0000000000..ec27291977 --- /dev/null +++ b/test/dialect/mssql.py @@ -0,0 +1,34 @@ +import testbase +import re +from sqlalchemy import * +from sqlalchemy.databases import mssql +from testlib import * + +msdialect = mssql.MSSQLDialect() + +# TODO: migrate all MS-SQL tests here + +class CompileTest(AssertMixin): + def _test(self, statement, expected, **params): + if len(params): + res = str(statement.compile(dialect=msdialect, parameters=params)) + else: + res = str(statement.compile(dialect=msdialect)) + res = re.sub(r'\n', '', res) + + assert res == expected, res + + def test_insert(self): + t = table('sometable', column('somecolumn')) + self._test(t.insert(), "INSERT INTO sometable (somecolumn) VALUES (:somecolumn)") + + def test_update(self): + t = table('sometable', column('somecolumn')) + self._test(t.update(t.c.somecolumn==7), "UPDATE sometable SET somecolumn=:somecolumn WHERE sometable.somecolumn = :sometable_somecolumn", somecolumn=10) + + def test_count(self): + t = table('sometable', column('somecolumn')) + self._test(t.count(), "SELECT count(sometable.somecolumn) AS tbl_row_count FROM sometable") + +if __name__ == "__main__": + testbase.main() diff --git a/test/engine/transaction.py b/test/engine/transaction.py index 8f1bb2d989..bd912a4df0 100644 --- a/test/engine/transaction.py +++ b/test/engine/transaction.py @@ -117,7 +117,7 @@ class TransactionTest(PersistTest): assert len(result.fetchall()) == 0 connection.close() - @testing.unsupported('sqlite', 'mssql') # TEMP: test causes mssql to hang + @testing.supported('postgres', 'mysql', 'oracle') @testing.exclude('mysql', '<', (5, 0, 3)) def testnestedsubtransactionrollback(self): connection = testbase.db.connect() @@ -135,7 +135,7 @@ class TransactionTest(PersistTest): ) connection.close() - @testing.unsupported('sqlite', 'mssql') # TEMP: test causes mssql to hang + @testing.supported('postgres', 'mysql', 'oracle') @testing.exclude('mysql', '<', (5, 0, 3)) def testnestedsubtransactioncommit(self): connection = testbase.db.connect() @@ -153,7 +153,7 @@ class TransactionTest(PersistTest): ) connection.close() - @testing.unsupported('sqlite', 'mssql') # TEMP: test causes mssql to hang + @testing.supported('postgres', 'mysql', 'oracle') @testing.exclude('mysql', '<', (5, 0, 3)) def testrollbacktosubtransaction(self): connection = testbase.db.connect() diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py index 8333dd5b60..cd92c89353 100644 --- a/test/orm/unitofwork.py +++ b/test/orm/unitofwork.py @@ -467,13 +467,13 @@ class ClauseAttributesTest(UnitOfWorkTest): metadata.create_all() def tearDown(self): - users_table.delete().execute() UnitOfWorkTest.tearDown(self) + users_table.delete().execute() def tearDownAll(self): metadata.drop_all() UnitOfWorkTest.tearDownAll(self) - + @testing.unsupported('mssql') # TEMP: test causes mssql to hang def test_update(self): class User(object): @@ -513,6 +513,7 @@ class ClauseAttributesTest(UnitOfWorkTest): assert u.name == 'test2' assert u.counter == 2 + @testing.unsupported('mssql') def test_insert(self): class User(object): pass @@ -682,12 +683,14 @@ class OneToManyTest(UnitOfWorkTest): def setUpAll(self): UnitOfWorkTest.setUpAll(self) tables.create() + def tearDownAll(self): tables.drop() UnitOfWorkTest.tearDownAll(self) + def tearDown(self): - tables.delete() UnitOfWorkTest.tearDown(self) + tables.delete() def testonetomany_1(self): """test basic save of one to many.""" @@ -907,8 +910,8 @@ class SaveTest(UnitOfWorkTest): ) def tearDown(self): - tables.delete() UnitOfWorkTest.tearDown(self) + tables.delete() def testbasic(self): # save two users @@ -1100,12 +1103,14 @@ class ManyToOneTest(UnitOfWorkTest): def setUpAll(self): UnitOfWorkTest.setUpAll(self) tables.create() + def tearDownAll(self): tables.drop() UnitOfWorkTest.tearDownAll(self) + def tearDown(self): - tables.delete() UnitOfWorkTest.tearDown(self) + tables.delete() def testm2oonetoone(self): # TODO: put assertion in here !!! @@ -1247,12 +1252,14 @@ class ManyToManyTest(UnitOfWorkTest): def setUpAll(self): UnitOfWorkTest.setUpAll(self) tables.create() + def tearDownAll(self): tables.drop() UnitOfWorkTest.tearDownAll(self) + def tearDown(self): - tables.delete() UnitOfWorkTest.tearDown(self) + tables.delete() def testmanytomany(self): items = orderitems @@ -1499,8 +1506,8 @@ class SaveTest2(UnitOfWorkTest): meta.create_all() def tearDown(self): - meta.drop_all() UnitOfWorkTest.tearDown(self) + meta.drop_all() def testbackwardsnonmatch(self): m = mapper(Address, addresses, properties = dict( -- 2.47.3