christopherbarsuk has asked for the wisdom of the Perl Monks concerning the following question:

I posted this message to the Q&A section, but it seems more appropriate in this section... see additional information below...

I'm using DBI with a MySQL database, and, reading through the documentation, I see the method 'selectcol_arrayref' -- when I try this method, it always returns 'undef'.

Q1: Is this method actually available?

Q2: Is there a way to determine what module is supplying an inherited method? That is, if I want to look at the code for this method, how do I determine where from it's being inherited?

Additional information: when I use selectcol_arrayref (using an SQL statement which evaluates fine in other methods), the DBI::errstr is empty, as is DBI::err -- that is, no error is occuring. However, I'm consistently getting back an 'undef' value, regardless of the query. This leads me to believe that the version of DBI that I'm using (or the MySQL driver) is somehow flawed...

I don't have root access, so I was hoping to trace the origin of this method and look at the code (if it exists -- for all I know, some AUTOLOAD statement is handling my request) -- but I'm not sure how to trace methods like this.

So... anybody know either if A: the selectcol_arrayref method is inactive in certain versions of DBI/its drivers? or B: how I can trace where this method is being originated?

Your gracious wisdom is much appreciated...

Replies are listed 'Best First'.
Re: problems with DBI::selectcol_arrayref
by chromatic (Archbishop) on Aug 10, 2001 at 23:40 UTC
    Set the RaiseError attribute on the DBI constructor, or check $DBI::errstr to see if there's an error message.

    The docs say you can also pass a prepared statement handle to selectcol_arrayref(), so try that as well.

    Finally, to read the code if you don't have root access, try perldoc -m DBI.

      Thanks for the response...

      ...$DBI::errstr is empty (as is $DBI::err, of course); tried passing a statement handle, with the same results.

      And, unfortunately, perldoc is broken on my system (I'll report it as a bug, but until the admin fixes it, I'm stuck)

      More and more I'm thinking I have a faulty DBI or DBD -- selectall_hashref is not working correctly, either.

        If Perldoc is broken on your system and you don't have root access, you might install Perl / DBI / MySQL on a system where you do have access.

        Installing this stuff yourself is time consuming. It might be worth the time to have access to the documentation and to have a reference system that isn't broken.

        It might not be worth the time to install MySQ at home, but ActiveState installs quickly. PPM gets wanted modules easier than CPAN... (Though ActiveState.com doesn't seem to be reachable from my current time and location)

Re: problems with DBI::selectcol_arrayref
by christopherbarsuk (Acolyte) on Aug 10, 2001 at 22:14 UTC
    More information:

    I'm having the same problem with selectall_hashref...

    For a properly formatted SQL statement, the following code:

    my $rl = $dbh->selectall_arrayref( $sql ); print ref $rl, "\n";

    yields: ARRAY. However, the following code:

    my $rl = $dbh->selectall_hashref( $sql ); print ref $rl, "\n";

    yields nothing (empty).

    What up?

Re: problems with DBI::selectcol_arrayref
by eejack (Hermit) on Aug 11, 2001 at 07:41 UTC
    You might want to check your version of DBI...some things have only been added relatively recently. Looking through the changes file for DBI might help.

    Also, selectcol_arrayref combines preparing and executing, so it is used against the database handle instead of the statement handle. For example:

    $dbh->selectcol_arrayref($statement); instead of $sth->selectcol_arrayref($statement);

    EEjack