Python Database Objects (PDO) 1.2.0 Released

Serge Orlov sombDELETE at pobox.ru
Wed Nov 19 02:35:16 EST 2003


"Jon Franz" <jfranz at neurokode.com> wrote in message news:mailman.861.1069206575.702.python-list at python.org...
> > > while results.next():
> > >     print "Name: " + results['Name'].value
> > >     print "Address: " + results['Address'].value
> > >     print "Size of 'Name' column in the db: " +
> str(results['Name'].length)
> >
> > 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.

Yes, if the .open() is an generator then it must return a sequence of items
but only one at a time. If the loop body doesn't keep the result object
it will be garbage collected pretty soon. You don't need to return
a dictionary you can return a special "coupler" object that will bind
the column description data (created only one time) with the column
values. Of course, it means one more allocation per row and extra
references, but I don't really think it's very expensive. After all it is
idiomatic iteration over a sequence. Without hard data to prove
that it's really expensive I don't think it's right to say it's expensive.

>
>
> > 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?
Sorry about my wording, you're using it as inteded of course, but when
I see any method with the name .next() used for iteration I immediately
think about python iterators. Then I realized I was wrong.

>
> It may help to quit thinking of a Resultset as a sequence of dictionaries -
> PDO explicitly avoids that.
Isn't it premature optimization?

-- Serge Orlov.






More information about the Python-list mailing list