Peter Gibbons wrote:
> 
> hello all,
> i'm looking for a DBD CSV basic example with two tables involved in a join.
> 
> Is this possible and if so can you provide a basic example..
> 
> many thanks
> Pete

DBD::CSV doesn't support SQL join statements, but it's possible to fake
them by combining two statement handles.  Here's a DBD::AnyData example
that should work just as well with DBD::CSV.

#
# This produces the same results as
# 
#     SELECT classes.pid,classes.title,profs.name 
#       FROM classes,profs
#      WHERE classes.pid = profs.pid
#
my $classes_sth = $dbh->prepare( "SELECT pid,title FROM classes" );
my $profs_sth   = $dbh->prepare( "SELECT name FROM profs WHERE pid = ?"
);
$classes_sth->execute;
while (my($pid,$class_title) = $classes_sth->fetchrow_array) {
    $profs_sth->execute($pid);
    my $row = $profs_sth->fetchrow_arrayref;
    my $prof_name = $row ? $row->[0] : '';
    print "$class_title : $prof_name\n";
}

-- 
Jeff

Reply via email to