[Bast-commits] r9782 - in SQL-Abstract/1.x/branches/log-sprintf: . lib/DBIx/Class/Storage/Debug

frew at dev.catalyst.perl.org frew at dev.catalyst.perl.org
Sat Oct 23 15:32:24 GMT 2010


Author: frew
Date: 2010-10-23 15:32:24 +0000 (Sat, 23 Oct 2010)
New Revision: 9782

Modified:
   SQL-Abstract/1.x/branches/log-sprintf/Changes
   SQL-Abstract/1.x/branches/log-sprintf/lib/DBIx/Class/Storage/Debug/PrettyPrint.pm
Log:
Add "no_repeats" option to fix it such that repeated SQL may be ellided except for placeholders?\194?\172


Modified: SQL-Abstract/1.x/branches/log-sprintf/Changes
===================================================================
--- SQL-Abstract/1.x/branches/log-sprintf/Changes	2010-10-23 15:30:42 UTC (rev 9781)
+++ SQL-Abstract/1.x/branches/log-sprintf/Changes	2010-10-23 15:32:24 UTC (rev 9782)
@@ -1,5 +1,7 @@
 Revision history for SQL::Abstract
 
+    - Add "no_repeats" option to fix it such that repeated SQL gets ellided
+      except for placeholders
     - Add stuff to take advantage of Log::Sprintf to give more information
       when tracing
 

Modified: SQL-Abstract/1.x/branches/log-sprintf/lib/DBIx/Class/Storage/Debug/PrettyPrint.pm
===================================================================
--- SQL-Abstract/1.x/branches/log-sprintf/lib/DBIx/Class/Storage/Debug/PrettyPrint.pm	2010-10-23 15:30:42 UTC (rev 9781)
+++ SQL-Abstract/1.x/branches/log-sprintf/lib/DBIx/Class/Storage/Debug/PrettyPrint.pm	2010-10-23 15:32:24 UTC (rev 9782)
@@ -10,17 +10,23 @@
 
 __PACKAGE__->mk_group_accessors( simple => '_sqlat' );
 __PACKAGE__->mk_group_accessors( simple => '_lsprint' );
+__PACKAGE__->mk_group_accessors( simple => '_last_sql' );
+__PACKAGE__->mk_group_accessors( simple => 'no_repeats' );
 
 sub new {
    my $class = shift;
    my $args = shift;
 
+   my $no_repeats = delete $args->{no_repeats};
    my $lsprint = Log::Sprintf->new(delete $args->{log_sprintf});
    my $sqlat = SQL::Abstract::Tree->new($args);
    my $self = $class->next::method(@_);
 
+   $self->no_repeats($no_repeats);
+
    $self->_sqlat($sqlat);
    $self->_lsprint($lsprint);
+   $self->_last_sql('');
 
    return $self
 }
@@ -35,11 +41,18 @@
   # DBIC pre-quotes bindargs
   $bindargs = [map { s/^'//; s/'$//; $_ } @{$bindargs}] if $use_placeholders;
 
-  my $formatted = $self->_sqlat->format($string, $bindargs) . "\n";
+  my $sqlat = $self->_sqlat;
+  my $formatted;
+  if ($self->no_repeats && $self->_last_sql eq $string) {
+     my ( $l, $r ) = @{ $sqlat->placeholder_surround };
+     $formatted = '... : ' . join(', ', map "$l$_$r", @$bindargs) . "\n";
+  } else {
+     $self->_last_sql($string);
+     $formatted = $sqlat->format($string, $bindargs) . "\n";
+     $formatted = "$formatted: " . join ', ', @{$bindargs}
+        unless $use_placeholders;
+  }
 
-  $formatted = "$formatted: " . join ', ', @{$bindargs}
-     unless $use_placeholders;
-
   $formatted = $self->_lsprint->sprintf({ message => $formatted });
 
   $self->next::method($formatted, @_);




More information about the Bast-commits mailing list