Hello monks, I have a module that our company code uses to establish a database handle. It specifically checks to see which databases are available, etc.. example below...
sub new_dbh { .... .... Establish the database handle Check other stuff, etc }
Later we are establishing our statement handle and executing code.... example...
$dbh = new_dbh({host=>'blablah'},{AutoCommit=>1}); $customer_handle="fred"; my $sth = $dbh->prepare(qq{select id from customer where handle=?}); $sth->execute($customer_handle);
So far, so textbook.....
What we are now needing to do is to append comments to our MySQL strings. Specifically the user id info

We can get that info by pulling out $ENV{USER} variable and the goal is to turn the SQL statement into one where the user id is is pre-pended to the statement... in our above example it needs to execute as ...
/* userid:jwilkie */ select id from customer where handle="fred";
We set the statement handle in about a million different places in our code and prepending the user id on every single statement handle is not realistic. Since the database handle is established in new_dbh, is there a way once the database handle is established that when the statement handle is executed, that we then pre-pend this user info in the new_dbh subroutine?

Definitely let me know if this isn't clear enough or if I can provide more info. The reason for this is so that we can get user id's in MySQL's slow query log. MySQL runs one user but we have users identifiable by their user id when they run scripts from the CLI.

In reply to Perl DBI: Overloading statement handle by sherab

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!
  • 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, details, 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, summary, 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.