in reply to Re: Re: DBD::CSV and SQL::Statement
in thread DBD::CSV and SQL::Statement

I like getting info straight from the horse's mouth, metaphorically speaking that is. I've installed DBD:RAM, very nice and easy to use.

Can you supply me with an example of how to use the multiple statement handles and doing nested fetch loops. I could probably figure it out, but since you offered---post it!!

Copied straight from the TODO's under DBD::CSV:

Joins
The current version of the module works with single table SELECTs only, although the basic design of the SQL::Statement module allows joins and the like.

Maybe I'm reading it wrong?! :)
  • Comment on Re: Re: Re: DBD::CSV and SQL::Statement

Replies are listed 'Best First'.
Re: Re: Re: Re: DBD::CSV and SQL::Statement
by jZed (Prior) on Mar 29, 2001 at 07:38 UTC
    Ok, first on SQL::Statement "the basic design ... allows joins". Yeah, right. The design allows it and if you want to implement it, all you have to do is implement it. :-) It's on my to-do list but it is not an easy task.

    Now for the example of accomplishing joins with multiple statement handles (this uses DBD::AnyData which is newer than DBD::RAM but except for the slightly different "catalog" syntax, it's the same with DBD::RAM:

    my $dbh=DBI->connect('dbi:AnyData(RaiseError=>1):');
    $dbh->func( 'Class', 'Pipe', 'class.tbl', 'ad_catalog');
    $dbh->func( 'Reg', 'Pipe', 'reg.tbl', 'ad_catalog');
    my $class_sth = $dbh->prepare( qq{SELECT cid,cname FROM Class} );
    my $reg_sth = $dbh->prepare( qq{SELECT sid FROM Reg WHERE cid = ?} );
    $class_sth->execute;
    while (my($cid,$cname) = $class_sth->fetchrow_array) {

    $reg_sth->execute($cid);
    my $sid = $reg_sth->fetchrow_arrayref->[0];
    print "$cid : $cname : $sid\n";
    }

    That will produce the same list that this statement would:

    SELECT Class.cid, Class.cname, Reg.sid
    FROM Class, Reg
    WHERE Class.cid = Reg.cid