Skip Menu |
 

This queue is for tickets about the DBIx-Simple CPAN distribution.

Report information
The Basics
Id: 71083
Status: open
Priority: 0/
Queue: DBIx-Simple

People
Owner: spamcollector_cpan [...] juerd.nl
Requestors: dagolden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Accessor for DBIx::Simple::Result statement handle
Download (untitled) / with headers
text/plain 223b
It would be helpful in some circumstances to have an accessor to the raw statement handle, rather than resorting to violating encapsulation by digging it out of the object hash. Please consider adding one. Regards, David
Download (untitled) / with headers
text/plain 605b
On Tue Sep 20 06:21:56 2011, DAGOLDEN wrote: Show quoted text
> It would be helpful in some circumstances to have an accessor to the raw > statement handle, rather than resorting to violating encapsulation by > digging it out of the object hash.
Allowing access to the statement handle breaks the reference management necessary for statement caching so I'm reluctant to exposing it. At least when you violate encapsulation, it's clear to everyone that you're doing something that wasn't part of the plan. Perhaps specific parts of the sth could be delegated explicitly. Which feature of the sth are you using? -- Juerd
Subject: Re: [rt.cpan.org #71083] Accessor for DBIx::Simple::Result statement handle
Date: Fri, 7 Oct 2011 07:06:28 -0400
To: bug-DBIx-Simple [...] rt.cpan.org
From: David Golden <dagolden [...] cpan.org>
Download (untitled) / with headers
text/plain 309b
On Fri, Oct 7, 2011 at 6:58 AM, Juerd Waalboer via RT <bug-DBIx-Simple@rt.cpan.org> wrote: Show quoted text
> Perhaps specific parts of the sth could be delegated explicitly. Which > feature of the sth are you using?
In this case, I was handing it off to Data::Stream::Bulk::DBI to get an iterator for the results. -- David
Download (untitled) / with headers
text/plain 1.4k
On Fri Oct 07 07:06:58 2011, DAGOLDEN wrote: Show quoted text
> In this case, I was handing it off to Data::Stream::Bulk::DBI to get > an iterator for the results.
That's a rather dangerous thing to do with DBIx::Simple. You'll have to be very careful to ensure that the DSBD object will not be longer lived than the DBIx::Simple::Result object. The DSBD has-a sth, but DSR assumes that it is the sole user of the same sth. Once the DSR is destroyed, it puts the sth in a pool for re-use. Executing the same query again while the old sth was still in use means that the original iterator will suddenly return results from the new query. I don't see a way to support this without me receiving many support requests from Perl programmers who don't understand these subtle internal interactions and action-at-a-distance, so I'm rejecting the wishlist item. DSBD is a very complicated way to fetch N rows at a time, by the way. I'd suggest simply doing that manually: sub n_arrays { my ($result, $n) = @_; my @rows; my $row; push @rows, @$row while $n-- and $row = $result->fetch; return @rows; } my $result = $db->query(...); while (my @chunk = n_arrays(100, $result)) { for (@chunk) { ... } } Or do you think DBIx::Simple should have this functionality built-in? while (@chunk = $result->arrays(100)) { ... } while (@chunk = $result->hashes(100)) { ... } while (@chunk = $result->objects(100)) { ... } -- Juerd
Subject: Re: [rt.cpan.org #71083] Accessor for DBIx::Simple::Result statement handle
Date: Tue, 11 Oct 2011 11:52:17 -0400
To: bug-DBIx-Simple [...] rt.cpan.org
From: David Golden <dagolden [...] cpan.org>
Download (untitled) / with headers
text/plain 1.1k
On Tue, Oct 11, 2011 at 11:24 AM, Juerd Waalboer via RT <bug-DBIx-Simple@rt.cpan.org> wrote: Show quoted text
> DSBD is a very complicated way to fetch N rows at a time, by the way. > I'd suggest simply doing that manually:
The more I understand DBI and DSBD, the more I see that it doesn't really work the way it's advertised. DSB gives a decent, standard interface for iteration over chunks, but I'd probably do something like your manual example. Show quoted text
> Or do you think DBIx::Simple should have this functionality built-in? > >    while (@chunk = $result->arrays(100)) { ... } >    while (@chunk = $result->hashes(100)) { ... } >    while (@chunk = $result->objects(100)) { ... }
Maybe. As you said, it's easy enough to do manually. I think it would be beneficial if the DB is able to operate asynchronously and start giving back results before the DB query finishes, but that's very DB-specific and thus maybe not worth adding to DBx::Simple. fetchall_arrayref with a "max results" option seems like it would be beneficial in such a case, but the more I dig into it, the less convinced I am that it works correctly for some common DBs I've tried it with. Please feel free to disregard my feature request. :-) -- David


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.