From 4530dff59282e04c2aa891c420d89d49fff11ae3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 3 Dec 2009 02:38:48 +0000 Subject: [PATCH] merge r6521 from trunk, [ticket:1632] --- CHANGES | 4 ++++ lib/sqlalchemy/pool.py | 5 ++++- test/engine/test_pool.py | 12 ++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 9bad50eb51..49e02e2aab 100644 --- a/CHANGES +++ b/CHANGES @@ -56,6 +56,10 @@ CHANGES elements to render correctly even if they all render identically, such as "qmark" style bind parameters. [ticket:1574] + + - The cursor associated with connection pool connections + (i.e. _CursorFairy) now proxies `__iter__()` to the + underlying cursor correctly. [ticket:1632] - postgresql - Added support for reflecting the DOUBLE PRECISION type, diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py index c4e1af20cf..7412b1a3c8 100644 --- a/lib/sqlalchemy/pool.py +++ b/lib/sqlalchemy/pool.py @@ -429,7 +429,10 @@ class _CursorFairy(object): def invalidate(self, e=None): self.__parent.invalidate(e=e) - + + def __iter__(self): + return iter(self.cursor) + def close(self): try: self.cursor.close() diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index d135ad337a..cffa42098b 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -1,7 +1,8 @@ import threading, time, gc from sqlalchemy import pool, interfaces import sqlalchemy as tsa -from sqlalchemy.test import TestBase +from sqlalchemy.test import TestBase, testing +from sqlalchemy.test.testing import eq_ mcid = 1 @@ -75,7 +76,14 @@ class PoolTest(PoolTestBase): self.assert_(connection.cursor() is not None) self.assert_(connection is not connection2) - + def test_cursor_iterable(self): + conn = testing.db.raw_connection() + cursor = conn.cursor() + cursor.execute("select 1") + expected = [(1,)] + for row in cursor: + eq_(row, expected.pop(0)) + def testthreadlocal_del(self): self._do_testthreadlocal(useclose=False) -- 2.47.3