Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

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

Here's a solution that doesn't use the callback mechanism, so it works with older versions of DBI. To use it, give it as the RootClass to DBI->connect. Since we were already using DBIx::ContextualFetch there, the code below uses that as its base, but it's not otherwise required.

package My::DatabaseRoot; use strict; use warnings; use base 'DBIx::ContextualFetch'; package My::DatabaseRoot::db; use base 'DBIx::ContextualFetch::db'; sub _rewrite { return $_[0] if ! defined $_[0]; return $_[0] if $_[0] =~ m{ COMPANY \s DEBUGGING \s INFO }xms; my $new_req = shift @_; # Add a newline, if there isn't one. $new_req =~ s{ ([^\n]) \z }{$1\n}xms; $new_req .= "/* COMPANY DEBUGGING INFO\n"; my $frame_num = 1; while ( my @frame_info = caller( $frame_num++ ) ) { $new_req .= "$frame_num. $frame_info[0]\::$frame_info[3] ($fra +me_info[1], line $frame_info[2])\n"; } $new_req .= "*/\n"; return $new_req; } my @methods = qw( do prepare prepare_cached selectrow_array selectrow_arrayref selectrow_hashref selectall_arrayref selectall_hashref selectcol_arrayref ); foreach my $method_name ( @methods ) { my $method = $method_name; no strict 'refs'; *{ __PACKAGE__ . "::$method" } = sub { my $self = shift @_; my $sql = _rewrite( shift @_ ); return $self->${ \"SUPER::$method" }( $sql, @_ ); }; } package LT::DatabaseRoot::st; use base 'DBIx::ContextualFetch::st'; 1; __END__ =pod =head1 NAME My::DatabaseRoot -- A class between the application and database =head1 SYNOPSIS DBI->connect( $dsn, $user, $pass, { RootClass => 'My::DatabaseRoot' } ); =head1 DESCRIPTION The purpose of My::DatabaseRoot is to get between the application and the database. Anything we want to do with our DBI access on a global basis can be added here. =head1 AUTHOR Kyle Hasselbacher =cut

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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (3)
    As of 2018-05-27 22:07 GMT
    Find Nodes?
      Voting Booth?