Python Database Objects (PDO) 1.2.0 Released
jfranz at neurokode.com
Wed Nov 19 02:54:34 CET 2003
> > while results.next():
> > print "Name: " + results['Name'].value
> > print "Address: " + results['Address'].value
> > print "Size of 'Name' column in the db: " +
> Why don't you use iterators for that?
> for result in mycon.open("SELECT * FROM Customers"):
> print ...
Individual rows are not objects in PDO.
Your idea for an iterator would call for something to be returned from
the .open(), such as a sequence of dictionaries, which would remove
the coupling of column values from the column description data.
Alternately, it would cause a repetition of the data (or at least many
extra references to it).
Keeping the descriptive info with the data (at least as far as how it's
accessed) was a design goal.
> Besides you're even "abusing" .next() method which you use to provide
> iterations in a different way. Confusing...
How is it abusive to use it the way it was intended?
It may help to quit thinking of a Resultset as a sequence of dictionaries -
PDO explicitly avoids that. The call to .next() is updating an internal
counter within the Resultset object, and returning a value based upon
whether the new position was in-bounds or not.
NeuroKode Labs, LLC
More information about the Python-list