On Thu, Nov 21, 2002 at 11:20:01AM -0500, Vorce, Tim (T.) wrote:
> I am selecting several columns.  I was hoping that that I could
> bring the columns into individual arrays, but that doesn't seem to
> be right.

> 
> the select "select 
>DSAA25_SITE_C,DSAA25_ROLE_C,DSAA25_SITETYPE_ID_C,DSAA25_COUNTRY_ISO3_C,DSAA25_JOBROLE_C,DSAA25_EMAILTYPE_C
> FROM mdsaa25_defaccess where DSAA02_APPLICATION_C='COOL' and DSAA03_TOKEN_C='Read' "
> 
> It looks like the bind column needs a fetch for each individual
> row, and that fetchall_arrayref has a structure that is not
> appropriate either.
> 
> What I am looking for is an output of arrays of each of those
> columns, ie
> 
> @sitecodes,@roles,@sitetypes,@countries,@jobroles,@emailtypes
> 
> Is there a construct to do that?????

You could take the return of fetchall_arrayref and massage it into
whatever you want...

    $res = $dbh->selectall_arrayref($sql);
    @sitecodes = map { $_->[0] } @$res;
    @roles     = map { $_->[1] } @$res;
    # etc..

It might be more efficient to build the arrays while the results are
returned, like this:

    $sth = $dbh->prepare($sql);
    $sth->execute;
    @refs = map { }
    $sth->bind_columns(\$site, \$role, ...);
    while ($sth->fetch) {
        push @sitecodes, $site;
        push @roles,     $role;
        # etc...
    }

I'm sure there are other ways to do it, too :)

(warning: above code should give you an idea, but was not tested)

-tim

Reply via email to