Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: Creating an iterator in a class

Reply
Thread Tools

RE: Creating an iterator in a class

 
 
Joseph L. Casale
Guest
Posts: n/a
 
      12-27-2012
> It's probably best if you use separate cursors anyway. Say you have
> two methods with a shared cursor:
>
> def iter_table_a(self):
> self.cursor.execute("SELECT * FROM TABLE_A")
> yield from self.cursor
>
> def iter_table_b(self):
> self.cursor.execute("SELECT * FROM TABLE_B")
> yield from self.cursor
>
> If the client code calls iter_table_a and partially iterates over the
> result, and then needs to use iter_table_b for some reason, then when
> it gets back to the table A results the data will be gone. You can
> only safely share cursors when you can guarantee that each query will
> be completely processed before the next query is run, and you can't
> guarantee that if you're just returning iterators.


Oops, I admit I never tested that scenario before and you are right, its
not a sane assumption.

Thanks, I'll rewrite that section.
jlc
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Creating an iterator in a class Ian Kelly Python 0 12-27-2012 06:35 PM
RE: Creating an iterator in a class Joseph L. Casale Python 0 12-27-2012 03:45 PM
Creating an iterator in a class Joseph L. Casale Python 1 12-27-2012 03:34 PM
Re: Creating an iterator in a class Peter Otten Python 0 12-27-2012 03:14 PM
Difference between Java iterator and iterator in Gang of Four Hendrik Maryns Java 18 12-22-2005 05:14 AM



Advertisments