[PEAK] Newbie Question

Phillip J. Eby pje at telecommunity.com
Sun Dec 21 17:13:28 EST 2003


At 11:12 AM 12/7/03 +0000, William Trenker wrote:

>But if I move the commitTransaction invocation up to just before the "for" 
>statement, the "rows" rowStruct is empty, like this:
>
>from peak.api import *
>class myDB(binding.Component):
>         db = binding.Obtain('sqlite:test.db')
>root = config.makeRoot()
>storage.beginTransaction(root)
>rows = myDB(root).db('select name,description from aTable')
>storage.commitTransaction(root)
>for row in rows:
>         print row.name, row.description
>
>(Nothing is printed)
>
>Why is the rows rowStruct empty in the 2nd scenario?  Has this got 
>something to do with PEAK's lazy binding feature?  Am I missing yet 
>another key concept here?

Glancing back through the list archives, I noticed this question hadn't 
been answered previously.  Sorry about that.

Anyway, the problem you're having is that cursors are closed at transaction 
boundaries.  If you want to retrieve the rows and then look at them outside 
the transaction, just do 'rows = list(rows)' which will convert the cursor 
into a list of row structs.

(Keep in mind that the return value of 'db("some SQL")' is an ICursor 
object, not a list of rows.)




More information about the PEAK mailing list