On Sep 23, 2010, at 5:20 AM, Jacek Kałucki wrote:
> I can't understand how to use this iterator.
It's simply a convenience method for looping through the rows of a
bizobj.
biz = self.PrimaryBizobj
biziter = biz.bizIterator()
for row in biziter:
print biz.Record.someField
> When I iterate through bizobj, I receive row number tuple:
> (0, 0), (1, 1), (2, 2), etc.
It returns an integer, not a tuple. The duplication is because you are
using enumerate(); the iterator returns the row number itself.
> Since bizobj is, in simplification, collection of rows,
> don't you think that I should rather receive tuple of row number and row
> itself,
> like (0, row0_object)?
Well, it could, but it would have to be separate from the bizobj
dataset. In other words, "biz.Record" is not a fixed set of data, but returns
whatever record the bizobj is pointed at at the moment. If it were to return
biz.Record instead of biz.RowNumber, you could not persist that reference.
Maybe an example would make that clearer: let's assume we have a bizobj with 10
rows, and a column named 'century'. Each row's 'century' column is 100 x the
row number: e.g., row 1 == 100, row 3 == 300, etc. Now consider this code,
which assumes that the iterator returns the biz.Record instead:
thirdrow = None
for rownum, record in biz.bizIterator():
if rownum == 3:
thirdrow = record
print thirdrow.century
Since we only captured the record on the third row, we would expect
'thirdrow.century' to be equal to 300, right? But it would be equal to 1000,
the value on the last record, since that's where the pointer is. Now consider
we did:
biz.first()
print thirdrow.century
Again, it would print 100, not 300.
The other option is to return the dataset tuple for that row. That
would fix the problem above, but would not allow you to modify that data and
have it update the bizobj. IOW, if you changed a value in the returned data, it
would not affect the data in the bizobj.
The whole purpose of the bizIterator is to avoid having to write code
like this:
biz.first()
while True:
try:
biz.dosomething()
biz.next()
except dabo.dException.EndOfFileException:
break
That's all it's meant to do.
-- Ed Leafe
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message:
http://leafe.com/archives/byMID/[email protected]