Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This is why my favorite DBI method is selectall_arrayref with the attribute Slice set

my $rows= $dbh->selectall_arrayref( "SELECT * FROM table", { Slice = +> {} } );

Sure it looks wonky and pretentious but this approach gives my an array reference of hash references where the hash key is the column name and the values are well, the data values. Now you can just use perl to get the size:

printf "Executed Statement - returned (%d) rows\n", scalar( @$rows ) +;

As a developer the concept of prepare, execute, and fetch is alluring and I can see its' value in certain situations but pragmatically, wrapping those steps into one is the common case with re-use of statement handle being the uncommon case (and for the future comments, I said uncommon - not rare). I am aware of the downsides to this approach such as the result set being too large and needing to be fetched in smaller batch sizes but I find a lot of the downsides to be outlier cases that are rarely hit (at least for my domain).

-derby

In reply to Re: SQLite: how to get a number of rows from SELECT query by derby
in thread SQLite: how to get a number of rows from SELECT query by igoryonya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2023-02-01 18:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (12 votes). Check out past polls.

    Notices?