Re: DBI: selectrow_array() return first column when called in list context

"[email protected]" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Message-ID <CAOqrB6YXN_bhL9QesDUJe+SkRg-Dezb=MR3v_XdfQ1QopyX9gw@mail.gmail.com>
I agree with you. I expected selectrow_array() to return an array whose
values should equal the number of columns in the query, but it does not
behave that way in my tests.


On 23 December 2013 22:35, Chad Wallace <[email protected]> wrote:

> On Mon, 23 Dec 2013 22:28:55 +0000
> Mimi Cafe <[email protected]> wrote:
>
> > This helped.
> >
> > > On 23 Dec 2013, at 15:28, Bruce Johnson
> > > <[email protected]> wrote:
> > >
> > >
> > >> On Dec 23, 2013, at 2:30 AM, [email protected] wrote:
> > >>
> > >> The SQL query is the same in both cases, and as can be seen, the
> > >> query is expected to return two columns (user and perm), but
> > >> selectrow_array() returns undef for the second column (perm in
> > >> this case).
> > >>
> > >> my ($x, $y)  = $dbh->selectrow_array(qq{SELECT user,perm FROM
> > >> access WHERE token=\'Tt9VpStL4xADSDJQtd4AkM
> > >> c6cVi66Mwmr9pMcCRgO4NVJ\'})|| die
> > >> "Could not query database:  $DBI::errstr\n";
> > >>
> > >> In the above, $y is undef (or blank) although MySQL has values for
> > >> both (user and perm) columns.
> > >
> > > The problem, which Martin correctly noted, is that  selectrow_array
> > > returns a single thing, an array containing the returned data.
> > >
> > > my ($x, $y)  = $dbh->selectrow_array(SQL);
> > >
> > > is giving you a pointer to the returned array, $x, and an undef $y.
>
> Hold on...  Am I missing something?
>
> What you seem to be saying, Bruce, is that selectrow_array() is exactly
> the same as selectrow_arrayref(). I am certain that's not the case.
> I've used both methods many times, and they are different.
>
> Is "a pointer to the returned array" not the same as "an array
> reference"?
>
>
>
>
> --
>
> C. Chad Wallace, B.Sc.
> The Lodging Company
> http://www.lodgingcompany.com/
> OpenPGP Public Key ID: 0x262208A0
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.