integrate placeholder population with DBIC
[dbsrgits/SQL-Abstract.git] / lib / DBIx / Class / Storage / Debug / PrettyPrint.pm
index ba6fbfc..4cae709 100644 (file)
@@ -1,5 +1,8 @@
 package DBIx::Class::Storage::Debug::PrettyPrint;
 
+use strict;
+use warnings;
+
 use base 'DBIx::Class::Storage::Statistics';
 
 use SQL::Abstract::Tree;
@@ -20,12 +23,33 @@ sub new {
 sub print {
   my $self = shift;
   my $string = shift;
+  my $bindargs = shift;
+
+  my $use_placeholders = !!$self->_sqlat->fill_in_placeholders;
+
+  # DBIC pre-quotes bindargs
+  $bindargs = [map { s/^'//; s/'$//; } @{$bindargs}] if $use_placeholders;
+
+  my $formatted = $self->_sqlat->format($string, $bindargs) . "\n";
 
-  my $formatted = $self->_sqlat->format($string);
+  $formatted = "$formatted: " . join ', ', @{$bindargs}
+     unless $use_placeholders;
 
   $self->next::method($formatted, @_);
 }
 
+sub query_start {
+  my ($self, $string, @bind) = @_;
+
+  if(defined $self->callback) {
+    $string =~ m/^(\w+)/;
+    $self->callback->($1, "$string: ".join(', ', @bind)."\n");
+    return;
+  }
+
+  $self->print($string, \@bind);
+}
+
 1;
 
 =pod