]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
some more mssql
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 2 Aug 2009 22:01:04 +0000 (22:01 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 2 Aug 2009 22:01:04 +0000 (22:01 +0000)
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/dialects/mssql/pyodbc.py
test/dialect/test_mssql.py
test/engine/test_execute.py
test/sql/test_returning.py

index e3fa1d4922da70d4f09476455c3ba853e81a8cdd..e1126532e11f0ea5ea228951fe8b2c5fd6e1d565 100644 (file)
@@ -861,12 +861,13 @@ class MSExecutionContext(default.DefaultExecutionContext):
                 self.cursor.execute("SELECT @@identity AS lastrowid")
             row = self.cursor.fetchall()[0]   # fetchall() ensures the cursor is consumed without closing it
             self._lastrowid = int(row[0])
-            
-        if self._enable_identity_insert:
-            self.cursor.execute("SET IDENTITY_INSERT %s OFF" % self.dialect.identifier_preparer.format_table(self.compiled.statement.table))
 
         if (self.isinsert or self.isupdate or self.isdelete) and self.compiled.returning:
             self._result_proxy = base.FullyBufferedResultProxy(self)
+
+        if self._enable_identity_insert:
+            self.cursor.execute("SET IDENTITY_INSERT %s OFF" % self.dialect.identifier_preparer.format_table(self.compiled.statement.table))
+
     
     def get_lastrowid(self):
         return self._lastrowid
index 5c5d2171a996e23f6e2cdc8aab257e4aeeb56e30..9a2a9e4e782c7c4e3446b82654016a6f8a6a49a5 100644 (file)
@@ -49,7 +49,7 @@ class MSExecutionContext_pyodbc(MSExecutionContext):
 
 
 class MSDialect_pyodbc(PyODBCConnector, MSDialect):
-    supports_sane_rowcount = False
+    supports_sane_rowcount = True
     supports_sane_multi_rowcount = False
 
     execution_ctx_cls = MSExecutionContext_pyodbc
index e2272c3ca4ee86d74338bd59ac9251983509e18c..05031c068b74707973feafe60b9548153d7f565e 100644 (file)
@@ -378,6 +378,19 @@ class QueryTest(TestBase):
             tbl.drop()
             con.execute('drop schema paj')
 
+    def test_returning_no_autoinc(self):
+        meta = MetaData(testing.db)
+        
+        table = Table('t1', meta, Column('id', Integer, primary_key=True), Column('data', String(50)))
+        table.create()
+        try:
+            result = table.insert().values(id=1, data=func.lower("SomeString")).returning(table.c.id, table.c.data).execute()
+            eq_(result.fetchall(), [(1, 'somestring',)])
+        finally:
+            # this will hang if the "SET IDENTITY_INSERT t1 OFF" occurs before the
+            # result is fetched
+            table.drop()
+
     def test_delete_schema(self):
         meta = MetaData(testing.db)
         con = testing.db.connect()
index e520a7b49593a535bd17613d5b27ac4cb158f9fe..d42ffc5c7ce1e78b2bfeb6a4672e634af36577c9 100644 (file)
@@ -88,8 +88,11 @@ class ExecuteTest(TestBase):
                                not testing.db.dialect.implicit_returning))
     def test_empty_insert(self):
         """test that execute() interprets [] as a list with no params"""
+        
         result = testing.db.execute(users.insert().values(user_name=bindparam('name')), [])
-        eq_(result.rowcount, 1)
+        eq_(testing.db.execute(users.select()).fetchall(), [
+            (1, None)
+        ])
 
 class ProxyConnectionTest(TestBase):
     @testing.fails_on('firebird', 'Data type unknown')
@@ -123,8 +126,8 @@ class ProxyConnectionTest(TestBase):
                         break
 
         for engine in (
-            engines.testing_engine(options=dict(proxy=MyProxy())),
-            engines.testing_engine(options=dict(proxy=MyProxy(), strategy='threadlocal'))
+            engines.testing_engine(options=dict(implicit_returning=False, proxy=MyProxy())),
+            engines.testing_engine(options=dict(implicit_returning=False, proxy=MyProxy(), strategy='threadlocal'))
         ):
             m = MetaData(engine)
 
@@ -136,6 +139,7 @@ class ProxyConnectionTest(TestBase):
                 t1.insert().execute(c1=6)
                 assert engine.execute("select * from t1").fetchall() == [(5, 'some data'), (6, 'foo')]
             finally:
+                pass
                 m.drop_all()
             
             engine.dispose()
index 04cfa4be8f820eb01e2d8d5b359c7eec5e34a61c..e076f3fe7c88cb045f9002910b8fe5089db80eab 100644 (file)
@@ -111,7 +111,8 @@ class ReturningTest(TestBase, AssertsExecutionResults):
 
         result3 = table.insert().returning(table.c.id).execute({'persons': 4, 'full': False})
         eq_([dict(row) for row in result3], [{'id': 4}])
-
+    
+        
     @testing.exclude('firebird', '<', (2, 1), '2.1+ feature')
     @testing.exclude('postgresql', '<', (8, 2), '8.3+ feature')
     @testing.fails_on_everything_except('postgresql', 'firebird')