Re: Help With Placeholders



PerlGoon wrote:

The
problem I have is that I need to be able to print the actual queries
my code runs into a log.... with the placeholders replaced.

For example, consider the following:

my $id = "example";
my $sql = "UPDATE Customers SET ID=?";
my $query = $db->prepare($sql);
$query->execute($id);

How do I print the ACTUAL query that was run into a log file.... with
the placeholders replaced???

You can replace each placeholder in the SQL statement with a value
calculated as $dbh->quote($_) for the next bind value.

You might be able to do that by overriding execute and putting the
logging in that method, though I bet it will not be easy: DBI is a very
hard module to subclass.

--
Bart.
.



Relevant Pages

  • Re: Log DBI query and values with placeholders
    ... Of course execute params are given dynamically and I want to use ... placeholders for more secure code. ... does not support 'SQL' tracing yet. ... You can also log such queries from ...
    (perl.dbi.users)
  • Re: Log DBI query and values with placeholders
    ... Of course execute params are given dynamically and I want to use ... placeholders for more secure code. ... does not support 'SQL' tracing yet. ... You can also log such queries from ...
    (perl.dbi.users)
  • Re: Help With Placeholders
    ... I use placeholders for all my queries. ... print $sql; ... UPDATE Customers SET ID='example' ...
    (comp.lang.perl.misc)
  • Help With Placeholders
    ... I use placeholders for all my queries. ... How do I print the ACTUAL query that was run into a log file.... ... UPDATE Customers SET ID='example' ...
    (comp.lang.perl.misc)
  • Re: Log DBI query and values with placeholders
    ... I need to log every INSERT, UPDATE and DELETE queries even when using ... Of course execute params are given dynamically and I want to use ... placeholders for more secure code. ... I want to save that UPDATE query into file or database (I'll prefer ...
    (perl.dbi.users)