# untested but realistic my $dbh = DBI->connect("...",{RaiseError => 1} ) or die "can't\n"; my $cust_sth = $dbh->prepare( qq{SELECT cust_ID, cust_name from customer}); $cust_sth->execute(); while (my $cust = $cust_sth->fetchrow_hashref()) { my $orders_sth = $dbh->prepare( qq{select * from orders where cust_ID = ? }); # do something smart with customer name $order_sth->execute($cust->{cust_ID}); while (my $order = $orders_sth->fetchrow_hashref()) { # do something even smarter with the orders data } }
With DBIx::Simple, I should either copy the result of the first query to an array, and suffer the copy delay, or create two objects (and bear in mind that in a real application I need to use more than that), thus having two connections and their relative overhead.

I didn't want to talk about statement handles, but I get the impression that you think DBIx::Simple can use only one. However, there are result objects, that internally are just objects holding a sth., with an alternative, consistent interface.

I don't think existing scripts should be re-written, but here's yours for demonstration purposes:

use DBIx::Simple; my $db = DBIx::Simple->connect("...",{RaiseError => 1} ) or die "can't +\n"; my $cust_result = $db->query('SELECT cust_ID, cust_name FROM customer' +); while (my $cust = $cust_result->hash) { my $orders_result = $db->query( 'SELECT * FROM orders WHERE cust_ID = ?', $cust->{cust_ID} ); while (my $order = $orders_result->hash) { # code } }
Or, when slurping into memory is not a problem, you can write beautiful code with DBIx::Simple:
use DBIx::Simple; my $db = DBIx::Simple->connect("...",{RaiseError => 1} ) or die "can't +\n"; for my $cust ($db->query('SELECT cust_ID, cust_name FROM customer')->h +ashes) { for my $order ($db->query('SELECT * FROM orders WHERE cust_ID = ?' +, $cust->{cust_ID}->hashes) { # code } }

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk


In reply to Re: Re: DBIx::Simple by Juerd
in thread DBIx::Simple by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.