Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: Quickest way of fetching a Single row and column in MySQL using DBI

by cees (Curate)
on Aug 07, 2006 at 18:01 UTC ( #565983=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Quickest way of fetching a Single row and column in MySQL using DBI
in thread Quickest way of fetching a Single row and column in MySQL using DBI

Scalar context works as well according to the DBI source code:

sub selectrow_array { my $row = _do_selectrow('fetchrow_arrayref', @_) or return; return $row->[0] unless wantarray; return @$row; }

The docs hint that this should work as well, but don't explicitly state it. Instead the docs mention this:

If called in a scalar context for a statement handle that has more than one column, it is undefined whether the driver will return the value of the first column or the last. So don't do that.

Anyway, it won't hurt to add the brackets in there to force list context, but it shouldn't be required.


Comment on Re^4: Quickest way of fetching a Single row and column in MySQL using DBI
Download Code
Re^5: Quickest way of fetching a Single row and column in MySQL using DBI
by jZed (Prior) on Aug 09, 2006 at 01:59 UTC
    Quoting the DBI docs is insufficient because the DBDs can override this. Forcing array context is not required because only a single column is being fetched regardless of which DBD is in use. Whenever more than one column is being fetched you should force list context if you care at all about portability. In scalar context, some DBDs return the first of the multiple columns and some return the last. Personally I try to always force the list context since it doesn't ever hurt and it sometimes helps.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://565983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-12-28 00:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls