]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed compiler bug in mssql
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 12 Aug 2007 21:36:33 +0000 (21:36 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 12 Aug 2007 21:36:33 +0000 (21:36 +0000)
- 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
lib/sqlalchemy/databases/mssql.py
test/dialect/alltests.py
test/dialect/mssql.py [new file with mode: 0755]
test/engine/transaction.py
test/orm/unitofwork.py

index 1dec5ede0f06f796e221efa49ce1f1dea12d01cb..8c7e6bb1cf1a6f5d82b802d6ee777d54fd25f68c 100644 (file)
@@ -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)
index 405b97617a0fa4a6fe6cfaeb1edb6256e631cef1..9ec0fbbc3872036794a14bd6fb284759c825d840 100644 (file)
@@ -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
index 8900736259cd9254250e3fffbe0ed4cb93a84f89..aeb754d5f8d1f97f880a5bfd3e63ffd2a7631280 100644 (file)
@@ -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 (executable)
index 0000000..ec27291
--- /dev/null
@@ -0,0 +1,34 @@
+import testbase\r
+import re\r
+from sqlalchemy import *\r
+from sqlalchemy.databases import mssql\r
+from testlib import *\r
+\r
+msdialect = mssql.MSSQLDialect()\r
+\r
+# TODO: migrate all MS-SQL tests here\r
+\r
+class CompileTest(AssertMixin):\r
+    def _test(self, statement, expected, **params):\r
+        if len(params):\r
+            res = str(statement.compile(dialect=msdialect, parameters=params))\r
+        else:\r
+            res = str(statement.compile(dialect=msdialect))\r
+        res = re.sub(r'\n', '', res)\r
+\r
+        assert res == expected, res\r
+        \r
+    def test_insert(self):\r
+        t = table('sometable', column('somecolumn'))\r
+        self._test(t.insert(), "INSERT INTO sometable (somecolumn) VALUES (:somecolumn)")\r
+\r
+    def test_update(self):\r
+        t = table('sometable', column('somecolumn'))\r
+       self._test(t.update(t.c.somecolumn==7), "UPDATE sometable SET somecolumn=:somecolumn WHERE sometable.somecolumn = :sometable_somecolumn", somecolumn=10)\r
+\r
+    def test_count(self):\r
+        t = table('sometable', column('somecolumn'))\r
+       self._test(t.count(), "SELECT count(sometable.somecolumn) AS tbl_row_count FROM sometable")\r
+    \r
+if __name__ == "__main__":\r
+    testbase.main()\r
index 8f1bb2d989bb044c1d234f1fbc9486ede14a8a6b..bd912a4df057030b53107f915b971fbffa64fa67 100644 (file)
@@ -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()
index 8333dd5b60f4825695c74f941d942a79c328fd33..cd92c89353ffee7ff6e36ca21f03867e60d0a3d1 100644 (file)
@@ -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(