LanX has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: DBI.pm: composing and debugging MySql placeholders
by neilwatson (Priest) on Oct 13, 2015 at 16:05 UTC | |
by LanX (Saint) on Oct 13, 2015 at 17:41 UTC | |
Re: DBI.pm: composing and debugging MySql placeholders
by mje (Curate) on Oct 13, 2015 at 16:40 UTC | |
by LanX (Saint) on Oct 13, 2015 at 17:45 UTC | |
Re: DBI.pm: composing and debugging MySql placeholders
by karlgoethebier (Abbot) on Oct 13, 2015 at 17:38 UTC |