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

"Martin J. Evans" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Organization at home
Message-ID <[email protected]>
On 20/12/2013 14:13, [email protected] wrote:
> Hi
>
> I need to understand why selectrow_array() return only one column (first
> column) when called in list context as in the code below. On the
> otherhand selectrow_arrayref behaves correctly.
>
> code
> =====

You've missed out how you actually called selectrow_array and that is 
the important bit.

I suspect you are not calling it in list context.

> if ($x){
>          print "When using selectrow_array(), DBI returned:";
>          print "\$x: $x \$y: $y";
>
>          print "\n\n";
> }else{
>          print "DB returned no data\n\n";
>
> }
>
> selectrow_arrayref behaves correctly.
>
> my ($arrref) = $dbh->selectrow_arrayref(qq{

You don't need brackets around $arrref here BTW. selectrow_arrayref only 
returns one value.

> SELECT user,perm FROM access
> WHERE token=\'Tt9VpStL4xADSDJQtd4AkMc6cVi66Mwmr9pMcCRgO4NVJ\'})|| die
> "Could not query database:  $DBI::errstr\n";
>
> my @retarr = @$arrref;
>
> if (@retarr){
>          print "When using selectrow_arrayref, DBI returned:";
>          print "\@retarr contains: @retarr ";
>
>          print "\n\n";
> }else{
>          print "DB returned no data\n\n";
>
> }
>
>
> Output
> =========
> perl misc_test.pl <http://misc_test.pl>
> Use of uninitialized value $y in concatenation (.) or string at
> misc_test.pl <http://misc_test.pl> line 69.
> When using selectrow_array(), DBI returned:$x: markb $y:
>
> When using selectrow_arrayref, DBI returned:@retarr contains: markb ro
>
>
> Installed versions
> ============
> perl -MDBD::mysql -le 'print $DBD::mysql::VERSION;'
> 4.013
>   perl -MDBI -le 'print $DBI::VERSION;'
> 1.609

Martin
-- 
Martin J. Evans
Wetherby, UK
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.