Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
The stupid question is the question not asked
 
PerlMonks  

Comment on

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

This is the solution I eventually came up with uses callbacks on methods that make a request to the database.

The important clues came from these two notes.

Thanks to everyone for their patient replies!

use strict; use warnings; use DBI; my $dbh = DBI->connect( 'DBI:mysql:database=xxx', 'xxx', 'xxx', { RaiseError => 1 } ); my $callback = sub { return if $_[1] =~ m{ \n-- \s* \S+ .* \n \z }xms; my $drh = shift @_; my $new_req = shift @_; my $method_name = $_; $new_req =~ s{ ([^\n]) \z }{$1\n}xms; my $frame_num = 1; while ( my @frame_info = caller( $frame_num++ ) ) { $new_req .= "-- $frame_info[3] ($frame_info[1], line $frame_in +fo[2])\n"; } undef $_; return $drh->can( $method_name )->( $drh, $new_req, @_ ); }; my @methods = qw( do prepare prepare_cached selectrow_array selectrow_arrayref selectrow_hashref selectall_arrayref selectall_hashref selectcol_arrayref ); foreach my $method ( @methods ) { $dbh->{Callbacks}{$method} = $callback; } junker(); sub junker { for ( 1 .. 1_000_000 ) { my @junk = $dbh->selectrow_array( 'SELECT 1' ); } } __END__ mysql> show processlist; +----+------+-----------+-------+---------+------+-----------+-------- +------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info + | +----+------+-----------+-------+---------+------+-----------+-------- +------------------------------------------------+ | 36 | root | localhost | xxxxx | Query | 0 | NULL | show pr +ocesslist | | 51 | root | localhost | xxxxx | Query | 0 | executing | SELECT +1 -- main::junker (/home/kyle/junk.pl, line 45) | +----+------+-----------+-------+---------+------+-----------+-------- +------------------------------------------------+ 2 rows in set (0.00 sec)

In reply to Re: Can DBI modify queries on the fly? (solution) by kyle
in thread Can DBI modify queries on the fly? by kyle

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (7)
    As of 2014-04-20 11:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (485 votes), past polls