]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed a regression in 0.6.4 whereby the change that
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 16 Sep 2010 15:29:01 +0000 (11:29 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 16 Sep 2010 15:29:01 +0000 (11:29 -0400)
allowed cursor errors to be raised consistently broke
the result.lastrowid accessor.   Test coverage has
been added for result.lastrowid.   Note that lastrowid
is only supported by Pysqlite and some MySQL drivers,
so isn't super-useful in the general case.

CHANGES
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/test/requires.py
test/sql/test_query.py

diff --git a/CHANGES b/CHANGES
index 35255cba42a0c6bbfbc7ae17cd20f7411dd03100..abcd25ef0424725f575c50f2161f4a68b11f7b8c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -83,7 +83,16 @@ CHANGES
     the "where type in (x, y, z)" is placed on the outside
     of the query only, instead of repeatedly.   May make
     some more adjustments to this.
-        
+
+- engine
+   
+   - Fixed a regression in 0.6.4 whereby the change that
+     allowed cursor errors to be raised consistently broke
+     the result.lastrowid accessor.   Test coverage has
+     been added for result.lastrowid.   Note that lastrowid
+     is only supported by Pysqlite and some MySQL drivers,
+     so isn't super-useful in the general case.
+     
 0.6.4
 =====
 - orm
index 79cadaea90187471d504ef4c91d8226358aec5c9..4d6912ce4b77bd8edb1bfff8061024627edea040 100644 (file)
@@ -2249,7 +2249,7 @@ class ResultProxy(object):
         self.context = context
         self.dialect = context.dialect
         self.closed = False
-        self.cursor = context.cursor
+        self.cursor = self._saved_cursor = context.cursor
         self.connection = context.root_connection
         self._echo = self.connection._echo and \
                         context.engine._should_log_debug()
@@ -2304,12 +2304,12 @@ class ResultProxy(object):
         regardless of database backend.
         
         """
-        return self.cursor.lastrowid
+        return self._saved_cursor.lastrowid
     
     def _cursor_description(self):
         """May be overridden by subclasses."""
         
-        return self.cursor.description
+        return self._saved_cursor.description
             
     def _autoclose(self):
         """called by the Connection to autoclose cursors that have no pending
index 501f0e24d9a7fdbbedcf570a1c94b0b8fa3dafa5..dc0b29228bc8aefe88dbc6929ca64d3883e5982b 100644 (file)
@@ -247,6 +247,12 @@ def sane_rowcount(fn):
         skip_if(lambda: not testing.db.dialect.supports_sane_rowcount)
     )
 
+def dbapi_lastrowid(fn):
+    return _chain_decorators_on(
+        fn,
+        fails_on_everything_except('mysql+mysqldb', 'sqlite+pysqlite')
+    )
+    
 def sane_multi_rowcount(fn):
     return _chain_decorators_on(
         fn,
index 2093e1f69c814cc78ecc7a1407c8bd67a2e27306..57f434a98714cb659b2956f69a8848148873326e 100644 (file)
@@ -619,6 +619,16 @@ class QueryTest(TestBase):
         eq_(r[users.c.user_name], 'jack')
         eq_(r.user_name, 'jack')
 
+    @testing.requires.dbapi_lastrowid
+    def test_native_lastrowid(self):
+        r = testing.db.execute(
+            users.insert(),
+            {'user_id':1, 'user_name':'ed'}
+        )
+        
+        eq_(r.lastrowid, 1)
+        
+        
     def test_graceful_fetch_on_non_rows(self):
         """test that calling fetchone() etc. on a result that doesn't
         return rows fails gracefully.