[Dbix-class] Get generated SQL

Mark Lawrence nomad at null.net
Tue Mar 11 15:01:18 GMT 2008


On Mon Mar 10, 2008 at 11:09:55AM -0400, John Goulah wrote:
> 
> We have some code for this written by Jeff Lanza,  I'm not sure its flawless
> but its a start :)

Here is an alternative implementation which I use in my code (is
actually an object method assuming a live DBI dbh in $self->dbh):

  sub query_as_string {
      my $self = shift;
      my $sql  = shift || croak 'query_as_string($sql, @bind_params)';

      foreach (@_) {
          if (defined($_) and $_ !~ /^[[:print:]]+$/) {
              $sql =~ s/\?/*BINARY DATA*/;
          }
          else {
              my $quote = $self->dbh->quote($_);
              $sql =~ s/\?/$quote/;
          }
      }
      return $sql;
  }

Feel free to use as you like.

Mark.
-- 
Mark Lawrence



More information about the DBIx-Class mailing list