Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.056 X-Spam-Evidence: '*H*': 0.89; '*S*': 0.00; 'cc:addr:python-list': 0.15; '-tkc': 0.16; 'chatty': 0.16; 'conn': 0.16; 'cursor': 0.16; 'cursor:': 0.16; 'datasets.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'row': 0.16; 'underlying': 0.16; '(but': 0.18; 'wrote:': 0.21; 'function': 0.22; 'header:In-Reply-To:1': 0.22; 'header:User- Agent:1': 0.23; 'structure': 0.23; "wouldn't": 0.24; 'cc:no real name:2**0': 0.26; 'memory': 0.27; 'cc:addr:python.org': 0.27; 'worked': 0.28; "i've": 0.28; 'hopefully': 0.29; 'skip:d 30': 0.29; 'surprised': 0.29; 'yeah,': 0.29; 'code': 0.29; 'stuff': 0.29; 'tim': 0.29; "i'd": 0.29; 'went': 0.30; "doesn't": 0.30; 'cc:2**0': 0.31; 'gets': 0.32; 'con': 0.33; "i'm": 0.36; 'but': 0.36; 'does': 0.36; 'something': 0.38; 'connection': 0.38; 'received:70': 0.38; 'being': 0.39; 'either': 0.39; 'large': 0.40; 'mar': 0.61; 'more': 0.63; 'believe': 0.67; '2012': 0.69; 'loop': 0.79; 'special': 0.79; '-0500,': 0.84; 'blow': 0.84; 'dennis': 0.84; 'efficiency,': 0.84; 'hood.': 0.84; 'iteration': 0.84; 'mxodbc': 0.84; 'received:50.22': 0.84; 'with,': 0.91; 'yours.': 0.95 Date: Mon, 26 Mar 2012 05:14:01 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 MIME-Version: 1.0 To: Dennis Lee Bieber Subject: Re: Documentation, assignment in expression. References: <4f6d0060$0$6634$9b4e6d93@newsspool2.arcor-online.net> <4f6f0d24$0$6561$9b4e6d93@newsspool4.arcor-online.net> <4F6F1792.1060709@tim.thechases.com> <4F6F222F.7050406@tim.thechases.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332756824 news.xs4all.nl 6971 [2001:888:2000:d::a6]:36571 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22170 On 03/25/12 17:59, Dennis Lee Bieber wrote: > On Sun, 25 Mar 2012 08:48:31 -0500, Tim Chase >> Yeah, it has the same structure internally, but I'm somewhat >> surprised that the DB connection object doesn't have an >> __iter__() that does something like this automatically under the >> covers. >> > I believe being able to use the connection object directly for > queries is considered a short-cut feature... If you use the longer form > > con = db.connect() > cur = con.cursor() > > the cursor object, in all that I've worked with, does function for > iteration > > for rec in cur: > #do stuff Interesting. Either this is something special for a particular DB back-end, or has been added since I went hunting (back with mxODBC and Python2.4). I wouldn't be surprised if the latter was the case, as my code is nigh identical to yours. conn = db.DriverConnect(connection_string) cursor = conn.cursor() cursor.execute(sql, params) for row in cursor: # in the above 2.4 + mxODBC, this fails process(row) I'd be interested to know the underlying implementation's efficiency, hopefully using .fetchmany() under the hood. My understanding is that the .fetchmany() loop is the best way to do it, as the .fetchone() gets chatty with the DB (but is more efficient if you only need one row from a multi-result query), and the .fetchall() can blow out memory on large datasets. -tkc