Honourable Monks,

For security reasons I'm trying to convince colleagues to start using placeholders in SQL prepared statements instead of using variable interpolation ( I don't want to discuss this further)

Now I'm getting the requirement to be able to show and log the resulting SQL statement of an ->execute() .

The motivation is to facilitate a cut&paste into an SQL GUI in case of problems.

There are multiple workarounds I could think of to mimic the process of ->bind_param() , but is there a proper way to use DBI.pm to get the analogous query after ->execute() ?

for instance this

my $statement = <<'__SQL__'; SELECT * FROM t_user_portal WHERE f_client = ? __SQL__ my $sth = $dbh->prepare($statement) or die $dbh->errstr; my $client='lanx'; my $rv = $sth->execute($client) or die $sth->errstr;

showing

SELECT * FROM t_user_portal WHERE f_client = 'lanx'

in case of problems?

I'm aware that MySql doesn't compose the query with placeholders by concatenating strings, it's rather something like:

PREPARE stmt1 FROM 'SELECT * FROM t_user_portal WHERE f_client = ?'; SET @client = 'lanx'; EXECUTE stmt1 USING @client;

which is still a acceptable for debugging (and easily constructable as a workaround).

So my question is:

Does DBI.pm show any resulting SQL-code from ->bind_param() or do I need to reconstruct the last code by myself after an error occurred?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!


In reply to DBI.pm: composing and debugging MySql placeholders by LanX

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.