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

Re: DBI Style Inquiry

by Ralesk (Pilgrim)
on Jun 27, 2013 at 11:50 UTC ( #1040995=note: print w/replies, xml ) Need Help??

in reply to DBI Style Inquiry

Generally, I do a my ($this, $that, $foo, $bar) = @_; at the start of my subs, rather than to access the @_ array directly. In case we’re talking about a method — where Perl will put the object as the first argument — it would go like this:

sub foo_method { my $self = shift; my ($this_arg, $that_arg, $whatever) = @_; ...; }

Another thing about DBI, I almost never use fetchrow_array anymore, but much more commonly use fetchrow_hashref which will allow you to refer to the returned columns by their names. Make sure to alias the columns with the SQL AS column_name phrase though.

Others have touched some other issues already, so I won’t repeat those.

Replies are listed 'Best First'.
Re^2: DBI Style Inquiry
by Tux (Abbot) on Jun 27, 2013 at 12:08 UTC

    But fetchrow_hashref is much slower than the other fetch methods. It doesn't really matter if you fetch just a single row, but when traversing thousands of records, you will notice. For speed use bind_columns (the last example of that section shows how to get the best of both worlds). Here are some (older) speed compares for different database types:

    Enjoy, Have FUN! H.Merijn

      Nice comparison. Would have probably been more interesting to see a graph that isn’t anchored on hashref = 100% though.

      I am surprised by the difference (even if it's small) between fetch and fetchrow_arrayref (your BC and DBC), as DBI docs say:

      "fetchrow_arrayref" $ary_ref = $sth->fetchrow_arrayref; $ary_ref = $sth->fetch; # alias

      Or is the essential difference something else?

      (Also, it would be interesting to have the DBMS version-numbers on those pages; it does say 2006, that's a long time ago. I would say that (arguably, no doubt) PostgreSQL has advanced more than the others in performance in this particular period)

        The difference between BC and DBC is the method-call overhead. If you really want to squeze out nonoseconds per call, it matters. It is not something I would propagate in use though:

        Create table 5000 x 12 Dbindcol 660153.156 recs/sec 4.8 x faster DBC bindcol 633472.697 recs/sec 4.6 x faster BC Darrayref 563380.282 recs/sec 4.1 x faster DAR arrayref 525486.075 recs/sec 3.8 x faster AR array 227086.929 recs/sec 1.7 x faster A hashref 136836.344 recs/sec HR

        Enjoy, Have FUN! H.Merijn

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-08-20 12:43 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (191 votes). Check out past polls.